Skip to content

Commit 9bd5d95

Browse files
committed
DEPR: deprecate get_ftype_counts (GH18243)
Deprecate NDFrame.get_ftype_counts()
1 parent 4a43815 commit 9bd5d95

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ Deprecations
740740

741741
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
742742
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
743+
- ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`)
743744

744745
.. _whatsnew_0230.prior_deprecations:
745746

pandas/core/generic.py

+41
Original file line numberDiff line numberDiff line change
@@ -4677,6 +4677,8 @@ def get_ftype_counts(self):
46774677
"""
46784678
Return counts of unique ftypes in this object.
46794679
4680+
.. deprecated:: 0.23.0
4681+
46804682
This is useful for SparseDataFrame or for DataFrames containing
46814683
sparse arrays.
46824684
@@ -4707,6 +4709,45 @@ def get_ftype_counts(self):
47074709
object:dense 1
47084710
dtype: int64
47094711
"""
4712+
warnings.warn("get_ftype_counts is deprecated and will "
4713+
"be removed in a future version",
4714+
FutureWarning, stacklevel=2)
4715+
return self._get_ftype_counts()
4716+
4717+
def _get_ftype_counts(self):
4718+
"""
4719+
Return counts of unique ftypes in this object.
4720+
4721+
This is useful for SparseDataFrame or for DataFrames containing
4722+
sparse arrays.
4723+
4724+
Returns
4725+
-------
4726+
dtype : Series
4727+
Series with the count of columns with each type and
4728+
sparsity (dense/sparse)
4729+
4730+
See Also
4731+
--------
4732+
ftypes : Return ftypes (indication of sparse/dense and dtype) in
4733+
this object.
4734+
4735+
Examples
4736+
--------
4737+
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
4738+
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
4739+
>>> df
4740+
str int float
4741+
0 a 1 1.0
4742+
1 b 2 2.0
4743+
2 c 3 3.0
4744+
4745+
>>> df._get_ftype_counts()
4746+
float64:dense 1
4747+
int64:dense 1
4748+
object:dense 1
4749+
dtype: int64
4750+
"""
47104751
from pandas import Series
47114752
return Series(self._data.get_ftype_counts())
47124753

pandas/tests/generic/test_generic.py

+8
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,11 @@ def test_pipe_panel(self):
10081008

10091009
with pytest.raises(ValueError):
10101010
result = wp.pipe((f, 'y'), x=1, y=1)
1011+
1012+
# GH18243
1013+
def test_get_ftype_counts_deprecated(self):
1014+
a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
1015+
df = DataFrame(a, columns=['str', 'int', 'float'])
1016+
1017+
with tm.assert_produces_warning(FutureWarning):
1018+
df.get_ftype_counts()

pandas/tests/series/test_dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_dtype(self):
6464
assert self.ts.ftypes == 'float64:dense'
6565
tm.assert_series_equal(self.ts.get_dtype_counts(),
6666
Series(1, ['float64']))
67-
tm.assert_series_equal(self.ts.get_ftype_counts(),
67+
tm.assert_series_equal(self.ts._get_ftype_counts(),
6868
Series(1, ['float64:dense']))
6969

7070
@pytest.mark.parametrize("value", [np.nan, np.inf])

0 commit comments

Comments
 (0)