Skip to content

Commit

Permalink
TEST-#6030: test the function parameters of Series.str accessor for…
Browse files Browse the repository at this point in the history
… pandas equivalence (#6033)

Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev authored May 22, 2023
1 parent b1dc45c commit 1e02633
Showing 1 changed file with 17 additions and 75 deletions.
92 changes: 17 additions & 75 deletions modin/pandas/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,76 +166,8 @@ def test_dataframe_api_equality():
allowed_different = ["to_hdf", "hist"]
# skip verifying .rename_axis() due to https://github.com/modin-project/modin/issues/5077
allowed_different.append("rename_axis")
difference = []

# Check that we don't have extra params
for m in modin_dir:
if m in allowed_different:
continue
try:
pandas_sig = dict(
inspect.signature(getattr(pandas.DataFrame, m)).parameters
)
except TypeError:
continue
try:
modin_sig = dict(inspect.signature(getattr(pd.DataFrame, m)).parameters)
except TypeError:
continue

if not pandas_sig == modin_sig:
append_val = (
m,
{
i: pandas_sig[i]
for i in pandas_sig.keys()
if i not in modin_sig
or pandas_sig[i].default != modin_sig[i].default
and not (
pandas_sig[i].default is np.nan
and modin_sig[i].default is np.nan
)
},
)
try:
# This validates that there are actually values to add to the difference
# based on the condition above.
if len(list(append_val[-1])[-1]) > 0:
difference.append(append_val)
except IndexError:
pass

assert not len(difference), "Missing params found in API: {}".format(difference)

# Check that we have all params
for m in modin_dir:
if m in allowed_different:
continue
try:
pandas_sig = dict(
inspect.signature(getattr(pandas.DataFrame, m)).parameters
)
except TypeError:
continue
try:
modin_sig = dict(inspect.signature(getattr(pd.DataFrame, m)).parameters)
except TypeError:
continue

if not pandas_sig == modin_sig:
append_val = (
m,
{i: modin_sig[i] for i in modin_sig.keys() if i not in pandas_sig},
)
try:
# This validates that there are actually values to add to the difference
# based on the condition above.
if len(list(append_val[-1])[-1]) > 0:
difference.append(append_val)
except IndexError:
pass

assert not len(difference), "Extra params found in API: {}".format(difference)
assert_parameters_eq((pandas.DataFrame, pd.DataFrame), modin_dir, allowed_different)


def test_series_str_api_equality():
Expand All @@ -250,6 +182,7 @@ def test_series_str_api_equality():
assert not len(extra_in_modin), "Differences found in API: {}".format(
extra_in_modin
)
assert_parameters_eq((pandas.Series.str, pd.Series.str), modin_dir, [])


def test_series_dt_api_equality():
Expand Down Expand Up @@ -330,17 +263,24 @@ def test_series_api_equality():
allowed_different = ["to_hdf", "hist"]
# skip verifying .rename_axis() due to https://github.com/modin-project/modin/issues/5077
allowed_different.append("rename_axis")

assert_parameters_eq((pandas.Series, pd.Series), modin_dir, allowed_different)


def assert_parameters_eq(objects, attributes, allowed_different):
pandas_obj, modin_obj = objects
difference = []

for m in modin_dir:
# Check that Modin functions/methods don't have extra params
for m in attributes:
if m in allowed_different:
continue
try:
pandas_sig = dict(inspect.signature(getattr(pandas.Series, m)).parameters)
pandas_sig = dict(inspect.signature(getattr(pandas_obj, m)).parameters)
except TypeError:
continue
try:
modin_sig = dict(inspect.signature(getattr(pd.Series, m)).parameters)
modin_sig = dict(inspect.signature(getattr(modin_obj, m)).parameters)
except TypeError:
continue

Expand All @@ -367,15 +307,17 @@ def test_series_api_equality():
pass
assert not len(difference), "Missing params found in API: {}".format(difference)

for m in modin_dir:
difference = []
# Check that Modin functions/methods have all params as pandas
for m in attributes:
if m in allowed_different:
continue
try:
pandas_sig = dict(inspect.signature(getattr(pandas.Series, m)).parameters)
pandas_sig = dict(inspect.signature(getattr(pandas_obj, m)).parameters)
except TypeError:
continue
try:
modin_sig = dict(inspect.signature(getattr(pd.Series, m)).parameters)
modin_sig = dict(inspect.signature(getattr(modin_obj, m)).parameters)
except TypeError:
continue

Expand Down

0 comments on commit 1e02633

Please sign in to comment.