Skip to content

TST: DataFrame.mad with nullable dtype #43170

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
merged 3 commits into from
Aug 23, 2021
Merged
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
42 changes: 42 additions & 0 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,48 @@ def test_minmax_extensionarray(method, numeric_only):
tm.assert_series_equal(result, expected)


def test_mad_nullable_integer():
# GH#33036
df = DataFrame(np.random.randn(100, 4).astype(np.int64))
df2 = df.astype("Int64")
Copy link
Member

Choose a reason for hiding this comment

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

Should this work with the any_signed_int_ea_dtype fixture?

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, updated


result = df2.mad()
expected = df.mad()
tm.assert_series_equal(result, expected)

result = df2.mad(axis=1)
expected = df.mad(axis=1)
tm.assert_series_equal(result, expected)

# case with NAs present
df2.iloc[::2, 1] = pd.NA

result = df2.mad()
expected = df.mad()
expected[1] = df.iloc[1::2, 1].mad()
tm.assert_series_equal(result, expected)

result = df2.mad(axis=1)
expected = df.mad(axis=1)
expected[::2] = df.T.loc[[0, 2, 3], ::2].mad()
tm.assert_series_equal(result, expected)


@pytest.mark.xfail(reason="GH#42895 caused by lack of 2D EA")
def test_mad_nullable_integer_all_na():
# GH#33036
df = DataFrame(np.random.randn(100, 4).astype(np.int64))
df2 = df.astype("Int64")

# case with all-NA row/column
df2.iloc[:, 1] = pd.NA # FIXME: this doesn't operate in-place
df2.iloc[:, 1] = pd.array([pd.NA] * len(df2), dtype="Int64")
result = df2.mad()
expected = df.mad()
expected[1] = pd.NA
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("meth", ["max", "min", "sum", "mean", "median"])
def test_groupby_regular_arithmetic_equivalent(meth):
# GH#40660
Expand Down