10000 DEPR: deprecate get_ftype_counts (GH18243) by GGordonGordon · Pull Request #20404 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: deprecate get_ftype_counts (GH18243) #20404

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DEPR: deprecate get_ftype_counts (GH18243)
Deprecate NDFrame.get_ftype_counts()
  • Loading branch information
GGordonGordon committed Mar 21, 2018
commit 4a0e2b3bb3372d2eda47e9db5bfd280428db6fc6
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ Deprecations

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

.. _whatsnew_0230.prior_deprecations:

Expand Down
41 changes: 41 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,8 @@ def get_ftype_counts(self):
"""
Return counts of unique ftypes in this object.

.. deprecated:: 0.23.0

This is useful for SparseDataFrame or for DataFrames containing
sparse arrays.

Expand Down Expand Up @@ -4707,6 +4709,45 @@ def get_ftype_counts(self):
object:dense 1
dtype: int64
"""
warnings.warn("get_ftype_counts is deprecated and will "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to create another function here, this is purely user facing (IOW don't create a _get_ftype_counts). keep the doc-string though.

"be removed in a future version",
FutureWarning, stacklevel=2)
return self._get_ftype_counts()

def _get_ftype_counts(self):
"""
Return counts of unique ftypes in this object.

This is useful for SparseDataFrame or for DataFrames containing
sparse arrays.

Returns
-------
dtype : Series
Series with the count of columns with each type and
sparsity (dense/sparse)

See Also
--------
ftypes : Return ftypes (indication of sparse/dense and dtype) in
this object.

Examples
--------
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
>>> df
str int float
0 a 1 1.0
1 b 2 2.0
2 c 3 3.0

>>> df._get_ftype_counts()
float64:dense 1
int64:dense 1
object:dense 1
dtype: int64
"""
from pandas import Series
return Series(self._data.get_ftype_counts())

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,11 @@ def test_pipe_panel(self):

with pytest.raises(ValueError):
result = wp.pipe((f, 'y'), x=1, y=1)

# GH18243
def test_get_ftype_counts_deprecated(self):
a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
df = DataFrame(a, columns=['str', 'int', 'float'])

with tm.assert_produces_warning(FutureWarning):
df.get_ftype_counts()
2 changes: 1 addition & 1 deletion pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_dtype(self):
assert self.ts.ftypes == 'float64:dense'
tm.assert_series_equal(self.ts.get_dtype_counts(),
Series(1, ['float64']))
tm.assert_series_equal(self.ts.get_ftype_counts(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just assert the warning here

tm.assert_series_equal(self.ts._get_ftype_counts(),
Series(1, ['float64:dense']))

@pytest.mark.parametrize("value", [np.nan, np.inf])
Expand Down
0