Skip to content

Commit 54c0d5a

Browse files
mroeschkejreback
authored andcommitted
DEPR: DataFrame.get_dtype_counts (#27145)
1 parent 647c635 commit 54c0d5a

29 files changed

+229
-180
lines changed

doc/source/getting_started/basics.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,11 +1968,11 @@ dtype of the column will be chosen to accommodate all of the data types
19681968
pd.Series([1, 2, 3, 6., 'foo'])
19691969
19701970
The number of columns of each type in a ``DataFrame`` can be found by calling
1971-
:meth:`~DataFrame.get_dtype_counts`.
1971+
``DataFrame.dtypes.value_counts()``.
19721972

19731973
.. ipython:: python
19741974
1975-
dft.get_dtype_counts()
1975+
dft.dtypes.value_counts()
19761976
19771977
Numeric dtypes will propagate and can coexist in DataFrames.
19781978
If a dtype is passed (either directly via the ``dtype`` keyword, a passed ``ndarray``,

doc/source/user_guide/io.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3767,7 +3767,7 @@ defaults to `nan`.
37673767
store.append('df_mixed', df_mixed, min_itemsize={'values': 50})
37683768
df_mixed1 = store.select('df_mixed')
37693769
df_mixed1
3770-
df_mixed1.get_dtype_counts()
3770+
df_mixed1.dtypes.value_counts()
37713771
37723772
# we have provided a minimum string column size
37733773
store.root.df_mixed.table

doc/source/user_guide/missing_data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pandas objects provide compatibility between ``NaT`` and ``NaN``.
105105
df2
106106
df2.loc[['a', 'c', 'h'], ['one', 'timestamp']] = np.nan
107107
df2
108-
df2.get_dtype_counts()
108+
df2.dtypes.value_counts()
109109
110110
.. _missing.inserting:
111111

doc/source/whatsnew/v0.10.1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You can now store ``datetime64`` in data columns
8989
store.append('df_mixed', df_mixed)
9090
df_mixed1 = store.select('df_mixed')
9191
df_mixed1
92-
df_mixed1.get_dtype_counts()
92+
df_mixed1.dtypes.value_counts()
9393
9494
You can pass ``columns`` keyword to select to filter a list of the return
9595
columns, this is equivalent to passing a

doc/source/whatsnew/v0.11.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Furthermore ``datetime64[ns]`` columns are created by default, when passed datet
296296
df
297297
298298
# datetime64[ns] out of the box
299-
df.get_dtype_counts()
299+
df.dtypes.value_counts()
300300
301301
# use the traditional nan, which is mapped to NaT internally
302302
df.loc[df.index[2:4], ['A', 'timestamp']] = np.nan

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ Other deprecations
786786
- :meth:`Index.item` and :meth:`Series.item` is deprecated. (:issue:`18262`)
787787
- The default value ``ordered=None`` in :class:`~pandas.api.types.CategoricalDtype` has been deprecated in favor of ``ordered=False``. When converting between categorical types ``ordered=True`` must be explicitly passed in order to be preserved. (:issue:`26336`)
788788
- :meth:`Index.contains` is deprecated. Use ``key in index`` (``__contains__``) instead (:issue:`17753`).
789+
- :meth:`DataFrame.get_dtype_counts` is deprecated. (:issue:`18262`)
789790
790791
.. _whatsnew_0250.prior_deprecations:
791792

pandas/core/computation/expressions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
7979
# check for dtype compatibility
8080
dtypes = set()
8181
for o in [a, b]:
82-
if hasattr(o, 'get_dtype_counts'):
83-
s = o.get_dtype_counts()
82+
if hasattr(o, 'dtypes'):
83+
s = o.dtypes.value_counts()
8484
if len(s) > 1:
8585
return False
86-
dtypes |= set(s.index)
86+
dtypes |= set(s.index.astype(str))
8787
elif isinstance(o, np.ndarray):
8888
dtypes |= {o.dtype.name}
8989

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ def _sizeof_fmt(num, size_qualifier):
23262326
else:
23272327
_verbose_repr()
23282328

2329-
counts = self.get_dtype_counts()
2329+
counts = self._data.get_dtype_counts()
23302330
dtypes = ['{k}({kk:d})'.format(k=k[0], kk=k[1]) for k
23312331
in sorted(counts.items())]
23322332
lines.append('dtypes: {types}'.format(types=', '.join(dtypes)))

pandas/core/generic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,6 +5263,10 @@ def get_dtype_counts(self):
52635263
"""
52645264
Return counts of unique dtypes in this object.
52655265
5266+
.. deprecated:: 0.25.0
5267+
5268+
Use `.dtypes.value_counts()` instead.
5269+
52665270
Returns
52675271
-------
52685272
dtype : Series
@@ -5288,6 +5292,10 @@ def get_dtype_counts(self):
52885292
object 1
52895293
dtype: int64
52905294
"""
5295+
warnings.warn("`get_dtype_counts` has been deprecated and will be "
5296+
"removed in a future version. For DataFrames use "
5297+
"`.dtypes.value_counts()", FutureWarning,
5298+
stacklevel=2)
52915299
from pandas import Series
52925300
return Series(self._data.get_dtype_counts())
52935301

pandas/tests/frame/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import pandas as pd
99
from pandas import (
10-
Categorical, DataFrame, Series, SparseDataFrame, compat, date_range,
11-
timedelta_range)
10+
Categorical, DataFrame, Series, SparseDataFrame, SparseDtype, compat,
11+
date_range, timedelta_range)
1212
import pandas.util.testing as tm
1313
from pandas.util.testing import (
1414
assert_almost_equal, assert_frame_equal, assert_series_equal)
@@ -433,11 +433,11 @@ def test_with_datetimelikes(self):
433433
'B': timedelta_range('1 day', periods=10)})
434434
t = df.T
435435

436-
result = t.get_dtype_counts()
436+
result = t.dtypes.value_counts()
437437
if self.klass is DataFrame:
438-
expected = Series({'object': 10})
438+
expected = Series({np.dtype('object'): 10})
439439
else:
440-
expected = Series({'Sparse[object, nan]': 10})
440+
expected = Series({SparseDtype(dtype=object): 10})
441441
tm.assert_series_equal(result, expected)
442442

443443

0 commit comments

Comments
 (0)