Skip to content

Commit 8814de9

Browse files
authored
TST: DataFrame.mad with nullable dtype (#43170)
* TST: DataFrame.mad with nullable dtype * Use any_signed_int_ea_dtype
1 parent 4a20781 commit 8814de9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pandas/tests/frame/test_reductions.py

+42
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,48 @@ def test_minmax_extensionarray(method, numeric_only):
16861686
tm.assert_series_equal(result, expected)
16871687

16881688

1689+
def test_mad_nullable_integer(any_signed_int_ea_dtype):
1690+
# GH#33036
1691+
df = DataFrame(np.random.randn(100, 4).astype(np.int64))
1692+
df2 = df.astype(any_signed_int_ea_dtype)
1693+
1694+
result = df2.mad()
1695+
expected = df.mad()
1696+
tm.assert_series_equal(result, expected)
1697+
1698+
result = df2.mad(axis=1)
1699+
expected = df.mad(axis=1)
1700+
tm.assert_series_equal(result, expected)
1701+
1702+
# case with NAs present
1703+
df2.iloc[::2, 1] = pd.NA
1704+
1705+
result = df2.mad()
1706+
expected = df.mad()
1707+
expected[1] = df.iloc[1::2, 1].mad()
1708+
tm.assert_series_equal(result, expected)
1709+
1710+
result = df2.mad(axis=1)
1711+
expected = df.mad(axis=1)
1712+
expected[::2] = df.T.loc[[0, 2, 3], ::2].mad()
1713+
tm.assert_series_equal(result, expected)
1714+
1715+
1716+
@pytest.mark.xfail(reason="GH#42895 caused by lack of 2D EA")
1717+
def test_mad_nullable_integer_all_na(any_signed_int_ea_dtype):
1718+
# GH#33036
1719+
df = DataFrame(np.random.randn(100, 4).astype(np.int64))
1720+
df2 = df.astype(any_signed_int_ea_dtype)
1721+
1722+
# case with all-NA row/column
1723+
df2.iloc[:, 1] = pd.NA # FIXME: this doesn't operate in-place
1724+
df2.iloc[:, 1] = pd.array([pd.NA] * len(df2), dtype=any_signed_int_ea_dtype)
1725+
result = df2.mad()
1726+
expected = df.mad()
1727+
expected[1] = pd.NA
1728+
tm.assert_series_equal(result, expected)
1729+
1730+
16891731
@pytest.mark.parametrize("meth", ["max", "min", "sum", "mean", "median"])
16901732
def test_groupby_regular_arithmetic_equivalent(meth):
16911733
# GH#40660

0 commit comments

Comments
 (0)