Skip to content
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

mypy typing issues for decimal pandas/tests/extension/decimal/test_decimal.py #28988

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 13 additions & 13 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,35 +110,35 @@ def assert_frame_equal(self, left, right, *args, **kwargs):
tm.assert_frame_equal(left, right, *args, **kwargs)


class TestDtype(BaseDecimal, base.BaseDtypeTests):
class TestDtype(BaseDecimal, base.BaseDtypeTests): # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

instead of silencing the mypy errors can you make the signatures of assert_series_equal and assert_frame_equal compatible between BaseDecimal and BaseExtensionTests.

make the methods in BaseDecimal staticmethods and define the methods in BaseExtensionTests to be compatibile using *args and **kwargs, i.e.

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tried putting staticmethod, BaseExtensionTests methods takes (left,right, some arguments) but BaseDecimal takes (left,right,*args,**kwargs) it is still showing incompatible by mypy, didn't find anything to solve this. I need to study more to solve this.

Copy link
Member

Choose a reason for hiding this comment

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

I think #28994 has the same issue. What error are you getting after trying what @simonjayhawkins suggested?

Copy link
Member

Choose a reason for hiding this comment

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

yes we have two modules that are reporting mypy errors due to the same root issue.

def test_hashable(self, dtype):
pass


class TestInterface(BaseDecimal, base.BaseInterfaceTests):
class TestInterface(BaseDecimal, base.BaseInterfaceTests): # type: ignore
pass


class TestConstructors(BaseDecimal, base.BaseConstructorsTests):
class TestConstructors(BaseDecimal, base.BaseConstructorsTests): # type: ignore
@pytest.mark.skip(reason="not implemented constructor from dtype")
def test_from_dtype(self, data):
# construct from our dtype & string dtype
pass


class TestReshaping(BaseDecimal, base.BaseReshapingTests):
class TestReshaping(BaseDecimal, base.BaseReshapingTests): # type: ignore
pass


class TestGetitem(BaseDecimal, base.BaseGetitemTests):
class TestGetitem(BaseDecimal, base.BaseGetitemTests): # type: ignore
def test_take_na_value_other_decimal(self):
arr = DecimalArray([decimal.Decimal("1.0"), decimal.Decimal("2.0")])
result = arr.take([0, -1], allow_fill=True, fill_value=decimal.Decimal("-1.0"))
expected = DecimalArray([decimal.Decimal("1.0"), decimal.Decimal("-1.0")])
self.assert_extension_array_equal(result, expected)


class TestMissing(BaseDecimal, base.BaseMissingTests):
class TestMissing(BaseDecimal, base.BaseMissingTests): # type: ignore
pass


Expand All @@ -163,7 +163,7 @@ class TestBooleanReduce(Reduce, base.BaseBooleanReduceTests):
pass


class TestMethods(BaseDecimal, base.BaseMethodsTests):
class TestMethods(BaseDecimal, base.BaseMethodsTests): # type: ignore
@pytest.mark.parametrize("dropna", [True, False])
@pytest.mark.xfail(reason="value_counts not implemented yet.")
def test_value_counts(self, all_data, dropna):
Expand All @@ -179,23 +179,23 @@ def test_value_counts(self, all_data, dropna):
tm.assert_series_equal(result, expected)


class TestCasting(BaseDecimal, base.BaseCastingTests):
class TestCasting(BaseDecimal, base.BaseCastingTests): # type: ignore
pass


class TestGroupby(BaseDecimal, base.BaseGroupbyTests):
class TestGroupby(BaseDecimal, base.BaseGroupbyTests): # type: ignore
@pytest.mark.xfail(
reason="needs to correctly define __eq__ to handle nans, xref #27081."
)
def test_groupby_apply_identity(self, data_for_grouping):
super().test_groupby_apply_identity(data_for_grouping)


class TestSetitem(BaseDecimal, base.BaseSetitemTests):
class TestSetitem(BaseDecimal, base.BaseSetitemTests): # type: ignore
pass


class TestPrinting(BaseDecimal, base.BasePrintingTests):
class TestPrinting(BaseDecimal, base.BasePrintingTests): # type: ignore
def test_series_repr(self, data):
# Overriding this base test to explicitly test that
# the custom _formatter is used
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_astype_dispatches(frame):
assert result.dtype.context.prec == ctx.prec


class TestArithmeticOps(BaseDecimal, base.BaseArithmeticOpsTests):
class TestArithmeticOps(BaseDecimal, base.BaseArithmeticOpsTests): # type: ignore
def check_opname(self, s, op_name, other, exc=None):
super().check_opname(s, op_name, other, exc=None)

Expand Down Expand Up @@ -298,7 +298,7 @@ def test_error(self):
pass


class TestComparisonOps(BaseDecimal, base.BaseComparisonOpsTests):
class TestComparisonOps(BaseDecimal, base.BaseComparisonOpsTests): # type: ignore
def check_opname(self, s, op_name, other, exc=None):
super().check_opname(s, op_name, other, exc=None)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ignore_errors=True
ignore_errors=True

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

Comment on lines 157 to 159
Copy link
Member

Choose a reason for hiding this comment

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

can you remove this entire section from setup.cfg

[mypy-pandas.tests.extension.json.array]
ignore_errors=True
Expand Down