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

ExtensionArray.Round method and tests #54582

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1125199
add round abc
andrewgsavage Aug 16, 2023
a4ef563
add round test
andrewgsavage Aug 16, 2023
9f6ebc9
round tests
andrewgsavage Aug 16, 2023
2f0f100
lint
andrewgsavage Aug 16, 2023
241ba6c
lint
andrewgsavage Aug 16, 2023
457290d
Merge branch 'main' into round
andrewgsavage Aug 17, 2023
e2a4168
tests
andrewgsavage Aug 26, 2023
a908700
move methods tests, elementwise rounding
andrewgsavage Sep 4, 2023
fbbfe46
lint
andrewgsavage Sep 5, 2023
15915dc
remove test
andrewgsavage Sep 5, 2023
4167122
Merge branch 'main' into round
andrewgsavage Sep 5, 2023
e31d06a
add default round method
andrewgsavage Sep 6, 2023
bfd36f8
merge main
andrewgsavage Sep 6, 2023
bc4d8c6
remove invert
andrewgsavage Sep 6, 2023
362cd73
typo
andrewgsavage Sep 6, 2023
aa79869
decimal array works now
andrewgsavage Sep 6, 2023
2b694bf
move round to base calss
andrewgsavage Sep 24, 2023
01d1453
move pytest mark into if statement
andrewgsavage Sep 24, 2023
e5d500d
nitpick
andrewgsavage Sep 24, 2023
95d07fa
fix pyarrow round dtypes
andrewgsavage Sep 24, 2023
f28d82f
implement sparsearray round
andrewgsavage Oct 19, 2023
2299134
lint
andrewgsavage Oct 19, 2023
15a7cac
lint
andrewgsavage Oct 19, 2023
ee37b4d
mypy
andrewgsavage Oct 19, 2023
70ebf5a
ignore my py error
andrewgsavage Nov 7, 2023
bda7031
Merge branch 'main' into round
andrewgsavage Nov 7, 2023
e01130d
remove blocks ignore mypyr
andrewgsavage Nov 7, 2023
2e73b6a
Merge branch 'round' of https://github.com/andrewgsavage/pandas into …
andrewgsavage Nov 7, 2023
2e9cddf
revert cast
andrewgsavage Nov 8, 2023
76c9ba7
typerror for non numerics
andrewgsavage Nov 8, 2023
044f0a1
isna
andrewgsavage Nov 8, 2023
770edf3
cast pyarrow
andrewgsavage Nov 9, 2023
85f67b6
Merge branch 'main' into round
andrewgsavage Mar 4, 2024
f3d4520
Update blocks.py
andrewgsavage Mar 4, 2024
398e64b
Update blocks.py
andrewgsavage Mar 4, 2024
b0af597
rounding boolean shouldnt error
andrewgsavage Mar 13, 2024
70b6c89
whatsnew
andrewgsavage Mar 13, 2024
8ef99da
Merge branch 'main' into round
andrewgsavage Jun 15, 2024
bebe0ac
Update v3.0.0.rst
andrewgsavage Jun 15, 2024
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
3 changes: 3 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,9 @@ def _add_logical_ops(cls) -> None:
setattr(cls, "__xor__", cls._create_logical_method(operator.xor))
setattr(cls, "__rxor__", cls._create_logical_method(roperator.rxor))

def round(self, decimals: int = 0, *args, **kwargs) -> Self:
andrewgsavage marked this conversation as resolved.
Show resolved Hide resolved
raise AbstractMethodError(self)


class ExtensionScalarOpsMixin(ExtensionOpsMixin):
"""
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/extension/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class TestMyDtype(BaseDtypeTests):
BaseArithmeticOpsTests,
BaseComparisonOpsTests,
BaseOpsUtil,
BaseRoundingTests,
BaseUnaryOpsTests,
)
from pandas.tests.extension.base.printing import BasePrintingTests
Expand Down Expand Up @@ -86,6 +87,7 @@ class ExtensionTests(
BaseArithmeticOpsTests,
BaseComparisonOpsTests,
BaseUnaryOpsTests,
BaseRoundingTests,
BasePrintingTests,
BaseReduceTests,
BaseReshapingTests,
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/extension/base/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,10 @@ def test_unary_ufunc_dunder_equivalence(self, data, ufunc):
else:
alt = ufunc(data)
tm.assert_extension_array_equal(result, alt)


class BaseRoundingTests:
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
def test_round(self, data):
result = pd.Series(data).round()
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
expected = pd.Series(np.round(data), dtype=data.dtype)
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
tm.assert_series_equal(result, expected)
6 changes: 6 additions & 0 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def test_invert(self, data):
@pytest.mark.parametrize("ufunc", [np.positive, np.negative, np.abs])
def test_unary_ufunc_dunder_equivalence(self, data, ufunc):
super().test_unary_ufunc_dunder_equivalence(data, ufunc)

@pytest.mark.xfail(
reason="DecimalArray.round is not implemented."
)
def test_round(self, data):
super().test_round(data)


def test_take_na_value_other_decimal():
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_EA_types(self, engine, data):
def test_invert(self, data):
super().test_invert(data)

@pytest.mark.xfail(
reason="IntervalArray.round is not implemented."
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
)
def test_round(self, data):
super().test_round(data)


# TODO: either belongs in tests.arrays.interval or move into base tests.
def test_fillna_non_scalar_raises(data_missing):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/extension/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,11 @@ def test_invert(self, data, request):

class Test2DCompat(base.Dim2CompatTests):
pass


class TestRounding(base.BaseRoundingTests):
def test_round(self, data, request):
if data.dtype == "boolean":
mark = pytest.mark.xfail(reason="Cannot round boolean dtype")
request.node.add_marker(mark)
super().test_round(data)