Skip to content

Commit c1e78b9

Browse files
Deprecate Groupby.dtypes (#13453)
This PR deprecates `Groupby.dtypes` since it is deprecated in `pandas-2.1` This PR fixes 5 pytests: ``` = 474 failed, 95510 passed, 2044 skipped, 763 xfailed, 300 xpassed in 459.93s (0:07:39) = ``` On `pandas_2.0_feature_branch`: ``` = 479 failed, 95505 passed, 2044 skipped, 763 xfailed, 300 xpassed in 471.66s (0:07:51) = ```
1 parent 7b13714 commit c1e78b9

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

python/cudf/cudf/core/_compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
PANDAS_LT_153 = PANDAS_VERSION < version.parse("1.5.3")
1212
PANDAS_EQ_200 = PANDAS_VERSION == version.parse("2.0.0")
1313
PANDAS_GE_200 = PANDAS_VERSION >= version.parse("2.0.0")
14+
PANDAS_GE_210 = PANDAS_VERSION >= version.parse("2.1.0")

python/cudf/cudf/core/groupby/groupby.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ def dtypes(self):
291291
"""
292292
Return the dtypes in this group.
293293
294+
.. deprecated:: 23.08
295+
Use `.dtypes` on base object instead.
296+
294297
Returns
295298
-------
296299
pandas.DataFrame
@@ -302,17 +305,23 @@ def dtypes(self):
302305
>>> df = cudf.DataFrame({'a': [1, 2, 3, 3], 'b': ['x', 'y', 'z', 'a'],
303306
... 'c':[10, 11, 12, 12]})
304307
>>> df.groupby("a").dtypes
305-
b c
308+
a b c
306309
a
307-
1 object int64
308-
2 object int64
309-
3 object int64
310+
1 int64 object int64
311+
2 int64 object int64
312+
3 int64 object int64
310313
"""
314+
warnings.warn(
315+
f"{type(self).__name__}.dtypes is deprecated and will be "
316+
"removed in a future version. Check the dtypes on the "
317+
"base object instead",
318+
FutureWarning,
319+
)
311320
index = self.grouping.keys.unique().sort_values().to_pandas()
312321
return pd.DataFrame(
313322
{
314323
name: [self.obj._dtypes[name]] * len(index)
315-
for name in self.grouping.values._column_names
324+
for name in self.obj._data.names
316325
},
317326
index=index,
318327
)

python/cudf/cudf/tests/test_groupby.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919

2020
import cudf
2121
from cudf import DataFrame, Series
22-
from cudf.core._compat import PANDAS_GE_150, PANDAS_LT_140, PANDAS_GE_200
22+
from cudf.core._compat import (
23+
PANDAS_GE_150,
24+
PANDAS_LT_140,
25+
PANDAS_GE_200,
26+
PANDAS_GE_210,
27+
)
2328
from cudf.core.udf.groupby_typing import SUPPORTED_GROUPBY_NUMPY_TYPES
2429
from cudf.core.udf.utils import precompiled
2530
from cudf.testing._utils import (
@@ -3100,8 +3105,12 @@ def test_groupby_dtypes(groups):
31003105
{"a": [1, 2, 3, 3], "b": ["x", "y", "z", "a"], "c": [10, 11, 12, 12]}
31013106
)
31023107
pdf = df.to_pandas()
3108+
with expect_warning_if(PANDAS_GE_210):
3109+
expected = pdf.groupby(groups).dtypes
3110+
with pytest.warns(FutureWarning):
3111+
actual = df.groupby(groups).dtypes
31033112

3104-
assert_eq(pdf.groupby(groups).dtypes, df.groupby(groups).dtypes)
3113+
assert_eq(expected, actual)
31053114

31063115

31073116
@pytest.mark.parametrize("index_names", ["a", "b", "c", ["b", "c"]])

0 commit comments

Comments
 (0)