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 5 commits
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
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
6 changes: 6 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,10 @@ 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)

from pandas import Series
return Series(self._data.get_ftype_counts())

Expand Down
66 changes: 6 additions & 60 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3396,11 +3396,8 @@ def map(self, mapper, na_action=None):

def isin(self, values, level=None):
"""
Return a boolean array where the index values are in `values`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert the changes here? Let me know if you need help with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TomAugspurger - I had removed it as you had requested to only have the deprecation code in the branch / PR. So just to clarify you do want this code back in this branch but you don't want that large pr file back in the branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sorry, that's exactly right. We want everything except the large pd file.

May be easiest to just re-add them manually in a new commit, rather than trying to mess with git.


Compute boolean array of whether each index value is found in the
passed set of values. The length of the returned boolean array matches
the length of the index.
passed set of values.

Parameters
----------
Expand All @@ -3409,74 +3406,23 @@ def isin(self, values, level=None):

.. versionadded:: 0.18.1

Support for values as a set.
Support for values as a set

level : str or int, optional
Name or position of the index level to use (if the index is a
`MultiIndex`).

Returns
-------
is_contained : ndarray
NumPy array of boolean values.

See also
--------
Series.isin : Same for Series.
DataFrame.isin : Same method for DataFrames.
MultiIndex).

Notes
-----
In the case of `MultiIndex` you must either specify `values` as a
list-like object containing tuples that are the same length as the
number of levels, or specify `level`. Otherwise it will raise a
``ValueError``.

If `level` is specified:

- if it is the name of one *and only one* index level, use that level;
- otherwise it should be a number indicating level position.

Examples
--------
>>> idx = pd.Index([1,2,3])
>>> idx
Int64Index([1, 2, 3], dtype='int64')

Check whether each index value in a list of values.
>>> idx.isin([1, 4])
array([ True, False, False])

>>> midx = pd.MultiIndex.from_arrays([[1,2,3],
... ['red', 'blue', 'green']],
... names=('number', 'color'))
>>> midx
MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],
labels=[[0, 1, 2], [2, 0, 1]],
names=['number', 'color'])

Check whether the strings in the 'color' level of the MultiIndex
are in a list of colors.

>>> midx.isin(['red', 'orange', 'yellow'], level='color')
array([ True, False, False])

To check across the levels of a MultiIndex, pass a list of tuples:

>>> midx.isin([(1, 'red'), (3, 'red')])
array([ True, False, False])

For a DatetimeIndex, string values in `values` are converted to
Timestamps.

>>> dates = ['2000-03-11', '2000-03-12', '2000-03-13']
>>> dti = pd.to_datetime(dates)
>>> dti
DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],
dtype='datetime64[ns]', freq=None)
Returns
-------
is_contained : ndarray (boolean dtype)

>>> dti.isin(['2000-03-11'])
array([ True, False, False])
"""
if level is not None:
self._validate_index_level(level)
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ 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

Series(1, ['float64:dense']))
# GH18243 - Assert .get_ftype_counts is deprecated
with tm.assert_produces_warning(FutureWarning):
tm.assert_series_equal(self.ts.get_ftype_counts(),
Series(1, ['float64:dense']))

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