Skip to content

REF: move misplaced tests #54440

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 2 commits into from
Aug 6, 2023
Merged
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
20 changes: 0 additions & 20 deletions pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,3 @@ def test_item(self, data):

with pytest.raises(ValueError, match=msg):
s.item()

def test_ellipsis_index(self):
# GH42430 1D slices over extension types turn into N-dimensional slices over
# ExtensionArrays
class CapturingStringArray(pd.arrays.StringArray):
"""Extend StringArray to capture arguments to __getitem__"""

def __getitem__(self, item):
self.last_item_arg = item
return super().__getitem__(item)

df = pd.DataFrame(
{"col1": CapturingStringArray(np.array(["hello", "world"], dtype=object))}
)
_ = df.iloc[:1]

# String comparison because there's no native way to compare slices.
# Before the fix for GH42430, last_item_arg would get set to the 2D slice
# (Ellipsis, slice(None, 1, None))
tm.assert_equal(str(df["col1"].array.last_item_arg), "slice(None, 1, None)")
24 changes: 0 additions & 24 deletions pandas/tests/extension/base/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,6 @@ def test_groupby_agg_extension(self, data_for_grouping):
result = df.groupby("A").first()
tm.assert_frame_equal(result, expected)

def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation(self):
# GH#41720
expected = pd.DataFrame(
{
"td": {
0: pd.Timedelta("0 days 01:00:00"),
1: pd.Timedelta("0 days 01:15:00"),
2: pd.Timedelta("0 days 01:15:00"),
}
}
)
df = pd.DataFrame(
{
"td": pd.Series(
["0 days 01:00:00", "0 days 00:15:00", "0 days 01:15:00"],
dtype="timedelta64[ns]",
),
"grps": ["a", "a", "b"],
}
)
gb = df.groupby("grps")
result = gb.agg(td=("td", "cumsum"))
tm.assert_frame_equal(result, expected)

def test_groupby_extension_no_sort(self, data_for_grouping):
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping})

Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/extension/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,26 @@ def test_astype_no_copy():
def test_is_extension_array_dtype(dtype):
assert isinstance(dtype, dtypes.ExtensionDtype)
assert is_extension_array_dtype(dtype)


class CapturingStringArray(pd.arrays.StringArray):
"""Extend StringArray to capture arguments to __getitem__"""

def __getitem__(self, item):
self.last_item_arg = item
return super().__getitem__(item)


def test_ellipsis_index():
# GH#42430 1D slices over extension types turn into N-dimensional slices
# over ExtensionArrays
df = pd.DataFrame(
{"col1": CapturingStringArray(np.array(["hello", "world"], dtype=object))}
)
_ = df.iloc[:1]

# String comparison because there's no native way to compare slices.
# Before the fix for GH#42430, last_item_arg would get set to the 2D slice
# (Ellipsis, slice(None, 1, None))
out = df["col1"].array.last_item_arg
assert str(out) == "slice(None, 1, None)"
25 changes: 25 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,3 +1606,28 @@ def test_agg_with_as_index_false_with_list():
columns=MultiIndex.from_tuples([("a1", ""), ("a2", ""), ("b", "sum")]),
)
tm.assert_frame_equal(result, expected)


def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation():
# GH#41720
expected = DataFrame(
{
"td": {
0: pd.Timedelta("0 days 01:00:00"),
1: pd.Timedelta("0 days 01:15:00"),
2: pd.Timedelta("0 days 01:15:00"),
}
}
)
df = DataFrame(
{
"td": Series(
["0 days 01:00:00", "0 days 00:15:00", "0 days 01:15:00"],
dtype="timedelta64[ns]",
),
"grps": ["a", "a", "b"],
}
)
gb = df.groupby("grps")
result = gb.agg(td=("td", "cumsum"))
tm.assert_frame_equal(result, expected)