Skip to content

Commit b71a817

Browse files
jbrockmendelmroeschke
authored andcommitted
REF: move misplaced tests (pandas-dev#54440)
* REF: move misplaced test * REF: move misplaced test
1 parent a1e5d05 commit b71a817

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

pandas/tests/extension/base/getitem.py

-20
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,3 @@ def test_item(self, data):
468468

469469
with pytest.raises(ValueError, match=msg):
470470
s.item()
471-
472-
def test_ellipsis_index(self):
473-
# GH42430 1D slices over extension types turn into N-dimensional slices over
474-
# ExtensionArrays
475-
class CapturingStringArray(pd.arrays.StringArray):
476-
"""Extend StringArray to capture arguments to __getitem__"""
477-
478-
def __getitem__(self, item):
479-
self.last_item_arg = item
480-
return super().__getitem__(item)
481-
482-
df = pd.DataFrame(
483-
{"col1": CapturingStringArray(np.array(["hello", "world"], dtype=object))}
484-
)
485-
_ = df.iloc[:1]
486-
487-
# String comparison because there's no native way to compare slices.
488-
# Before the fix for GH42430, last_item_arg would get set to the 2D slice
489-
# (Ellipsis, slice(None, 1, None))
490-
tm.assert_equal(str(df["col1"].array.last_item_arg), "slice(None, 1, None)")

pandas/tests/extension/base/groupby.py

-24
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,6 @@ def test_groupby_agg_extension(self, data_for_grouping):
6767
result = df.groupby("A").first()
6868
tm.assert_frame_equal(result, expected)
6969

70-
def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation(self):
71-
# GH#41720
72-
expected = pd.DataFrame(
73-
{
74-
"td": {
75-
0: pd.Timedelta("0 days 01:00:00"),
76-
1: pd.Timedelta("0 days 01:15:00"),
77-
2: pd.Timedelta("0 days 01:15:00"),
78-
}
79-
}
80-
)
81-
df = pd.DataFrame(
82-
{
83-
"td": pd.Series(
84-
["0 days 01:00:00", "0 days 00:15:00", "0 days 01:15:00"],
85-
dtype="timedelta64[ns]",
86-
),
87-
"grps": ["a", "a", "b"],
88-
}
89-
)
90-
gb = df.groupby("grps")
91-
result = gb.agg(td=("td", "cumsum"))
92-
tm.assert_frame_equal(result, expected)
93-
9470
def test_groupby_extension_no_sort(self, data_for_grouping):
9571
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping})
9672

pandas/tests/extension/test_common.py

+23
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,26 @@ def test_astype_no_copy():
7878
def test_is_extension_array_dtype(dtype):
7979
assert isinstance(dtype, dtypes.ExtensionDtype)
8080
assert is_extension_array_dtype(dtype)
81+
82+
83+
class CapturingStringArray(pd.arrays.StringArray):
84+
"""Extend StringArray to capture arguments to __getitem__"""
85+
86+
def __getitem__(self, item):
87+
self.last_item_arg = item
88+
return super().__getitem__(item)
89+
90+
91+
def test_ellipsis_index():
92+
# GH#42430 1D slices over extension types turn into N-dimensional slices
93+
# over ExtensionArrays
94+
df = pd.DataFrame(
95+
{"col1": CapturingStringArray(np.array(["hello", "world"], dtype=object))}
96+
)
97+
_ = df.iloc[:1]
98+
99+
# String comparison because there's no native way to compare slices.
100+
# Before the fix for GH#42430, last_item_arg would get set to the 2D slice
101+
# (Ellipsis, slice(None, 1, None))
102+
out = df["col1"].array.last_item_arg
103+
assert str(out) == "slice(None, 1, None)"

pandas/tests/groupby/aggregate/test_aggregate.py

+25
Original file line numberDiff line numberDiff line change
@@ -1606,3 +1606,28 @@ def test_agg_with_as_index_false_with_list():
16061606
columns=MultiIndex.from_tuples([("a1", ""), ("a2", ""), ("b", "sum")]),
16071607
)
16081608
tm.assert_frame_equal(result, expected)
1609+
1610+
1611+
def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation():
1612+
# GH#41720
1613+
expected = DataFrame(
1614+
{
1615+
"td": {
1616+
0: pd.Timedelta("0 days 01:00:00"),
1617+
1: pd.Timedelta("0 days 01:15:00"),
1618+
2: pd.Timedelta("0 days 01:15:00"),
1619+
}
1620+
}
1621+
)
1622+
df = DataFrame(
1623+
{
1624+
"td": Series(
1625+
["0 days 01:00:00", "0 days 00:15:00", "0 days 01:15:00"],
1626+
dtype="timedelta64[ns]",
1627+
),
1628+
"grps": ["a", "a", "b"],
1629+
}
1630+
)
1631+
gb = df.groupby("grps")
1632+
result = gb.agg(td=("td", "cumsum"))
1633+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)