Skip to content

Commit

Permalink
Fix str_cat/extract/partition/replace/rpartition (modin-project#51) (…
Browse files Browse the repository at this point in the history
…core)
  • Loading branch information
helmeleegy authored and vnlitvinov committed Mar 16, 2023
1 parent 5e02f8f commit c727887
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions modin/pandas/series_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ def casefold(self):
def cat(self, others=None, sep=None, na_rep=None, join=None):
if isinstance(others, Series):
others = others._to_pandas()
return self._default_to_pandas(
pandas.Series.str.cat, others=others, sep=sep, na_rep=na_rep, join=join
data = Series(query_compiler=self._query_compiler)
return data._reduce_dimension(
self._query_compiler.str_cat(
others=others, sep=sep, na_rep=na_rep, join=join
)
)

def decode(self, encoding, errors="strict"):
Expand Down Expand Up @@ -307,7 +310,10 @@ def match(self, pat, case=True, flags=0, na=np.NaN):
)

def extract(self, pat, flags=0, expand=True):
if expand:
import re

n = re.compile(pat).groups
if expand or n > 1:
from .dataframe import DataFrame

return DataFrame(
Expand Down Expand Up @@ -337,9 +343,21 @@ def lstrip(self, to_strip=None):
def partition(self, sep=" ", expand=True):
if sep is not None and len(sep) == 0:
raise ValueError("empty separator")
return Series(
query_compiler=self._query_compiler.str_partition(sep=sep, expand=expand)
)

if expand:
from .dataframe import DataFrame

return DataFrame(
query_compiler=self._query_compiler.str_partition(
sep=sep, expand=expand
)
)
else:
return Series(
query_compiler=self._query_compiler.str_partition(
sep=sep, expand=expand
)
)

def removeprefix(self, prefix):
return Series(query_compiler=self._query_compiler.str_removeprefix(prefix))
Expand All @@ -353,11 +371,21 @@ def repeat(self, repeats):
def rpartition(self, sep=" ", expand=True):
if sep is not None and len(sep) == 0:
raise ValueError("empty separator")
return Series(
query_compiler=self._query_compiler.str_rpartition(
sep=sep, expand=expand

if expand:
from .dataframe import DataFrame

return DataFrame(
query_compiler=self._query_compiler.str_rpartition(
sep=sep, expand=expand
)
)
else:
return Series(
query_compiler=self._query_compiler.str_rpartition(
sep=sep, expand=expand
)
)
)

def lower(self):
return Series(query_compiler=self._query_compiler.str_lower())
Expand Down

0 comments on commit c727887

Please sign in to comment.