Skip to content

Commit 270549a

Browse files
committed
Changes in tests and warning
1 parent f7e2d59 commit 270549a

File tree

3 files changed

+63
-64
lines changed

3 files changed

+63
-64
lines changed

pandas/core/groupby/groupby.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,6 @@ def _resolve_numeric_only(self, numeric_only: bool | lib.NoDefault) -> bool:
11201120
obj = self._obj_with_exclusions
11211121
check = obj._get_numeric_data()
11221122
if len(obj.columns) and not len(check.columns) and not obj.empty:
1123-
warnings.warn("... Explicitly pass numeric_only ...")
11241123
numeric_only = False
11251124

11261125
else:

pandas/tests/groupby/aggregate/test_aggregate.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -117,69 +117,6 @@ def test_groupby_aggregation_mixed_dtype():
117117
tm.assert_frame_equal(result, expected)
118118

119119

120-
def test_groupby_aggregation_non_numeric_dtype():
121-
# GH #43108
122-
df = DataFrame(
123-
[["M", [1]], ["M", [1]], ["W", [10]], ["W", [20]]], columns=["MW", "v"]
124-
)
125-
126-
expected = DataFrame(
127-
{
128-
"v": [[1, 1], [10, 20]],
129-
},
130-
index=Index(["M", "W"], dtype="object", name="MW"),
131-
)
132-
133-
with tm.assert_produces_warning(UserWarning):
134-
g = df.groupby(by=["MW"])
135-
result = g.sum()
136-
tm.assert_frame_equal(result, expected)
137-
138-
139-
def test_groupby_aggregation_multi_non_numeric_dtype():
140-
# GH #42395
141-
df = DataFrame(
142-
{
143-
"x": [1, 0, 1, 1, 0],
144-
"y": [Timedelta(i, "days") for i in range(1, 6)],
145-
"z": [Timedelta(i * 10, "days") for i in range(1, 6)],
146-
}
147-
)
148-
149-
expected = DataFrame(
150-
{
151-
"y": [Timedelta(i, "days") for i in range(7, 9)],
152-
"z": [Timedelta(i * 10, "days") for i in range(7, 9)],
153-
},
154-
index=Int64Index([0, 1], dtype="int64", name="x"),
155-
)
156-
157-
with tm.assert_produces_warning(UserWarning):
158-
g = df.groupby(by=["x"])
159-
result = g.sum()
160-
tm.assert_frame_equal(result, expected)
161-
162-
163-
def test_groupby_aggregation_numeric_with_non_numeric_dtype():
164-
# GH #43108
165-
df = DataFrame(
166-
{
167-
"x": [1, 0, 1, 1, 0],
168-
"y": [Timedelta(i, "days") for i in range(1, 6)],
169-
"z": [i for i in range(1, 6)],
170-
}
171-
)
172-
173-
expected = DataFrame(
174-
{"z": [7, 8]},
175-
index=Int64Index([0, 1], dtype="int64", name="x"),
176-
)
177-
178-
g = df.groupby(by=["x"])
179-
result = g.sum()
180-
tm.assert_frame_equal(result, expected)
181-
182-
183120
def test_groupby_aggregation_multi_level_column():
184121
# GH 29772
185122
lst = [

pandas/tests/groupby/test_function.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,69 @@ def _check(self, df, method, expected_columns, expected_columns_numeric):
262262

263263
tm.assert_index_equal(result.columns, expected_columns)
264264

265+
def test_groupby_aggregation_non_numeric_dtype():
266+
# GH #43108
267+
df = DataFrame(
268+
[["M", [1]], ["M", [1]], ["W", [10]], ["W", [20]]], columns=["MW", "v"]
269+
)
270+
271+
expected = DataFrame(
272+
{
273+
"v": [[1, 1], [10, 20]],
274+
},
275+
index=Index(["M", "W"], dtype="object", name="MW"),
276+
)
277+
278+
279+
gb = df.groupby(by=["MW"])
280+
result = gb.sum()
281+
tm.assert_frame_equal(result, expected)
282+
283+
284+
def test_groupby_aggregation_multi_non_numeric_dtype():
285+
# GH #42395
286+
df = DataFrame(
287+
{
288+
"x": [1, 0, 1, 1, 0],
289+
"y": [Timedelta(i, "days") for i in range(1, 6)],
290+
"z": [Timedelta(i * 10, "days") for i in range(1, 6)],
291+
}
292+
)
293+
294+
expected = DataFrame(
295+
{
296+
"y": [Timedelta(i, "days") for i in range(7, 9)],
297+
"z": [Timedelta(i * 10, "days") for i in range(7, 9)],
298+
},
299+
index=Int64Index([0, 1], dtype="int64", name="x"),
300+
)
301+
302+
303+
gb = df.groupby(by=["x"])
304+
result = gb.sum()
305+
tm.assert_frame_equal(result, expected)
306+
307+
308+
def test_groupby_aggregation_numeric_with_non_numeric_dtype():
309+
# GH #43108
310+
df = DataFrame(
311+
{
312+
"x": [1, 0, 1, 1, 0],
313+
"y": [Timedelta(i, "days") for i in range(1, 6)],
314+
"z": [i for i in range(1, 6)],
315+
}
316+
)
317+
318+
expected = DataFrame(
319+
{"z": [7, 8]},
320+
index=Int64Index([0, 1], dtype="int64", name="x"),
321+
)
322+
323+
gb = df.groupby(by=["x"])
324+
result = gb.sum()
325+
tm.assert_frame_equal(result, expected)
326+
327+
265328

266329
class TestGroupByNonCythonPaths:
267330
# GH#5610 non-cython calls should not include the grouper

0 commit comments

Comments
 (0)