Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def replace(self, pat, repl, n=-1, case=None, flags=0, regex=True):
if not (is_string_like(repl) or callable(repl)):
raise TypeError("repl must be a string or callable")
return Series(
query_compiler=self._query_compiler.str_replace(
pat, repl, n=n, case=case, flags=flags, regex=regex
)
def swapcase(self):
return Series(query_compiler=self._query_compiler.str_swapcase())
def _reduce_dimension(self, query_compiler):
return Series(query_compiler=query_compiler)
def _create_or_update_from_compiler(self, new_query_compiler, inplace=False):
"""Returns or updates a DataFrame given new query_compiler"""
assert (
isinstance(new_query_compiler, type(self._query_compiler))
or type(new_query_compiler) in self._query_compiler.__class__.__bases__
), "Invalid Query Compiler object: {}".format(type(new_query_compiler))
if not inplace and (
len(new_query_compiler.columns) == 1 or len(new_query_compiler.index) == 1
):
return Series(query_compiler=new_query_compiler)
elif not inplace:
# This can happen with things like `reset_index` where we can add columns.
from .dataframe import DataFrame
return DataFrame(query_compiler=new_query_compiler)
else:
self._update_inplace(new_query_compiler=new_query_compiler)
def find(self, sub, start=0, end=None):
if not isinstance(sub, str):
raise TypeError(
"expected a string object, not {0}".format(type(sub).__name__)
)
return Series(
query_compiler=self._query_compiler.str_find(sub, start=start, end=end)
)
def upper(self):
return Series(query_compiler=self._query_compiler.str_upper())
def _prepare_inter_op(self, other):
if isinstance(other, Series):
new_self = self.copy()
new_self.name = "__reduced__"
new_other = other.copy()
new_other.name = "__reduced__"
else:
new_self = self
new_other = other
return new_self, new_other
def normalize(self, form):
return Series(query_compiler=self._query_compiler.str_normalize(form))
def translate(self, table):
return Series(query_compiler=self._query_compiler.str_translate(table))
def append(self, other, ignore_index=False, verify_integrity=False, sort=None):
"""Append another DataFrame/list/Series to this one.
Args:
other: The object to append to this.
ignore_index: Ignore the index on appending.
verify_integrity: Verify the integrity of the index on completion.
Returns:
A new DataFrame containing the concatenated values.
"""
if isinstance(other, (Series, dict)):
if isinstance(other, dict):
other = Series(other)
if other.name is None and not ignore_index:
raise TypeError(
"Can only append a Series if ignore_index=True"
" or if the Series has a name"
)
if other.name is not None:
# other must have the same index name as self, otherwise
# index name will be reset
name = other.name
# We must transpose here because a Series becomes a new row, and the
# structure of the query compiler is currently columnar
other = other._query_compiler.transpose()
other.index = pandas.Index([name], name=self.index.name)
else:
# See note above about transpose
other = other._query_compiler.transpose()