Skip to content

fixed mypy errors in mypy-pandas.tests.extension.decimal.test_decimal #31730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pandas/tests/extension/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@


class BaseExtensionTests:
# can't use staticmethod() as this confuses mypy
@staticmethod
def assert_equal(left, right, **kwargs):
return tm.assert_equal(left, right, **kwargs)

assert_equal = staticmethod(tm.assert_equal)
assert_series_equal = staticmethod(tm.assert_series_equal)
assert_frame_equal = staticmethod(tm.assert_frame_equal)
assert_extension_array_equal = staticmethod(tm.assert_extension_array_equal)
@staticmethod
def assert_series_equal(left, right, *args, **kwargs):
return tm.assert_series_equal(left, right, *args, **kwargs)

@staticmethod
def assert_frame_equal(left, right, *args, **kwargs):
return tm.assert_frame_equal(left, right, *args, **kwargs)

@staticmethod
def assert_extension_array_equal(left, right, *args, **kwargs):
return tm.assert_extension_array_equal(left, right, *args, **kwargs)
8 changes: 5 additions & 3 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def data_for_grouping():


class BaseDecimal:
def assert_series_equal(self, left, right, *args, **kwargs):
@staticmethod
def assert_series_equal(left, right, *args, **kwargs):
def convert(x):
# need to convert array([Decimal(NaN)], dtype='object') to np.NaN
# because Series[object].isnan doesn't recognize decimal(NaN) as
Expand All @@ -88,7 +89,8 @@ def convert(x):
tm.assert_series_equal(left_na, right_na)
return tm.assert_series_equal(left[~left_na], right[~right_na], *args, **kwargs)

def assert_frame_equal(self, left, right, *args, **kwargs):
@staticmethod
def assert_frame_equal(left, right, *args, **kwargs):
# TODO(EA): select_dtypes
tm.assert_index_equal(
left.columns,
Expand All @@ -103,7 +105,7 @@ def assert_frame_equal(self, left, right, *args, **kwargs):
decimals = (left.dtypes == "decimal").index

for col in decimals:
self.assert_series_equal(left[col], right[col], *args, **kwargs)
BaseDecimal.assert_series_equal(left[col], right[col], *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it should be a classmethod

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the advantage of using classmethod over staticmethod? I typically only use classmethod if I need multiple ways of instantiation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having BaseDecimal hard-coded here looks like a kludge, I'm speculating that what you want here is cls.assert_series_equal, kind of halfway inbetween the regular method it is now and the staticmethod in the PR


left = left.drop(columns=decimals)
right = right.drop(columns=decimals)
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ ignore_errors=True
[mypy-pandas.tests.arithmetic.test_datetime64]
ignore_errors=True

[mypy-pandas.tests.extension.decimal.test_decimal]
ignore_errors=True

[mypy-pandas.tests.extension.json.test_json]
ignore_errors=True

Expand Down