Skip to content
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

DEPR: Categorical.ravel, get_dtype_counts, dtype_str, to_dense #29900

Merged
merged 11 commits into from
Dec 1, 2019
Merged
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def setup(self):

def time_frame_get_dtype_counts(self):
with warnings.catch_warnings(record=True):
self.df.get_dtype_counts()
self.df._data.get_dtype_counts()

def time_info(self):
self.df.info()
Expand Down
5 changes: 0 additions & 5 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ generated/pandas.DataFrame.from_dict,../reference/api/pandas.DataFrame.from_dict
generated/pandas.DataFrame.from_items,../reference/api/pandas.DataFrame.from_items
generated/pandas.DataFrame.from_records,../reference/api/pandas.DataFrame.from_records
generated/pandas.DataFrame.ge,../reference/api/pandas.DataFrame.ge
generated/pandas.DataFrame.get_dtype_counts,../reference/api/pandas.DataFrame.get_dtype_counts
generated/pandas.DataFrame.get,../reference/api/pandas.DataFrame.get
generated/pandas.DataFrame.get_value,../reference/api/pandas.DataFrame.get_value
generated/pandas.DataFrame.get_values,../reference/api/pandas.DataFrame.get_values
Expand Down Expand Up @@ -486,7 +485,6 @@ generated/pandas.DataFrame.T,../reference/api/pandas.DataFrame.T
generated/pandas.DataFrame.timetuple,../reference/api/pandas.DataFrame.timetuple
generated/pandas.DataFrame.to_clipboard,../reference/api/pandas.DataFrame.to_clipboard
generated/pandas.DataFrame.to_csv,../reference/api/pandas.DataFrame.to_csv
generated/pandas.DataFrame.to_dense,../reference/api/pandas.DataFrame.to_dense
generated/pandas.DataFrame.to_dict,../reference/api/pandas.DataFrame.to_dict
generated/pandas.DataFrame.to_excel,../reference/api/pandas.DataFrame.to_excel
generated/pandas.DataFrame.to_feather,../reference/api/pandas.DataFrame.to_feather
Expand Down Expand Up @@ -632,7 +630,6 @@ generated/pandas.Index.drop,../reference/api/pandas.Index.drop
generated/pandas.Index.droplevel,../reference/api/pandas.Index.droplevel
generated/pandas.Index.dropna,../reference/api/pandas.Index.dropna
generated/pandas.Index.dtype,../reference/api/pandas.Index.dtype
generated/pandas.Index.dtype_str,../reference/api/pandas.Index.dtype_str
generated/pandas.Index.duplicated,../reference/api/pandas.Index.duplicated
generated/pandas.Index.empty,../reference/api/pandas.Index.empty
generated/pandas.Index.equals,../reference/api/pandas.Index.equals
Expand Down Expand Up @@ -1046,7 +1043,6 @@ generated/pandas.Series.floordiv,../reference/api/pandas.Series.floordiv
generated/pandas.Series.from_array,../reference/api/pandas.Series.from_array
generated/pandas.Series.from_csv,../reference/api/pandas.Series.from_csv
generated/pandas.Series.ge,../reference/api/pandas.Series.ge
generated/pandas.Series.get_dtype_counts,../reference/api/pandas.Series.get_dtype_counts
generated/pandas.Series.get,../reference/api/pandas.Series.get
generated/pandas.Series.get_value,../reference/api/pandas.Series.get_value
generated/pandas.Series.get_values,../reference/api/pandas.Series.get_values
Expand Down Expand Up @@ -1235,7 +1231,6 @@ generated/pandas.Series.T,../reference/api/pandas.Series.T
generated/pandas.Series.timetuple,../reference/api/pandas.Series.timetuple
generated/pandas.Series.to_clipboard,../reference/api/pandas.Series.to_clipboard
generated/pandas.Series.to_csv,../reference/api/pandas.Series.to_csv
generated/pandas.Series.to_dense,../reference/api/pandas.Series.to_dense
generated/pandas.Series.to_dict,../reference/api/pandas.Series.to_dict
generated/pandas.Series.to_excel,../reference/api/pandas.Series.to_excel
generated/pandas.Series.to_frame,../reference/api/pandas.Series.to_frame
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Attributes and underlying data
:toctree: api/

DataFrame.dtypes
DataFrame.get_dtype_counts
DataFrame.select_dtypes
DataFrame.values
DataFrame.get_values
Expand Down Expand Up @@ -363,7 +362,6 @@ Serialization / IO / conversion
DataFrame.to_msgpack
DataFrame.to_gbq
DataFrame.to_records
DataFrame.to_dense
DataFrame.to_string
DataFrame.to_clipboard
DataFrame.style
1 change: 0 additions & 1 deletion doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Properties
Index.has_duplicates
Index.hasnans
Index.dtype
Index.dtype_str
Index.inferred_type
Index.is_all_dates
Index.shape
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ Serialization / IO / conversion
Series.to_sql
Series.to_msgpack
Series.to_json
Series.to_dense
Series.to_string
Series.to_clipboard
Series.to_latex
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- In :func:`concat` the default value for ``sort`` has been changed from ``None`` to ``False`` (:issue:`20613`)
- Removed previously deprecated "raise_conflict" argument from :meth:`DataFrame.update`, use "errors" instead (:issue:`23585`)
- Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`)
- Removed the previously deprecated :meth:`Series.to_dense`, :meth:`DataFrame.to_dense` (:issue:`26684`)
- Removed the previously deprecated :meth:`Index.dtype_str`, use ``str(index.dtype)`` instead (:issue:`27106`)
- :meth:`Categorical.ravel` returns a :class:`Categorical` instead of a ``ndarray`` (:issue:`27199`)
- Removed previously deprecated :meth:`Series.get_dtype_counts` and :meth:`DataFrame.get_dtype_counts` (:issue:`27145`)
- Changed the default ``fill_value`` in :meth:`Categorical.take` from ``True`` to ``False`` (:issue:`20841`)
- Changed the default value for the `raw` argument in :func:`Series.rolling().apply() <pandas.core.window.Rolling.apply>`, :func:`DataFrame.rolling().apply() <pandas.core.window.Rolling.apply>`,
- :func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` to ``False`` (:issue:`20584`)
Expand Down
18 changes: 0 additions & 18 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,24 +1689,6 @@ def _values_for_rank(self):
)
return values

def ravel(self, order="C"):
"""
Return a flattened (numpy) array.

For internal compatibility with numpy arrays.

Returns
-------
numpy.array
"""
warn(
"Categorical.ravel will return a Categorical object instead "
"of an ndarray in a future version.",
FutureWarning,
stacklevel=2,
)
return np.array(self)

def view(self, dtype=None):
if dtype is not None:
raise NotImplementedError(dtype)
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,6 @@ def is_sparse(arr) -> bool:
bool
Whether or not the array-like is a pandas sparse array.

See Also
--------
Series.to_dense : Return dense representation of a Series.

Examples
--------
Returns `True` if the parameter is a 1-D pandas sparse array.
Expand Down
67 changes: 1 addition & 66 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class NDFrame(PandasObject, SelectionMixin):
]
_internal_names_set: Set[str] = set(_internal_names)
_accessors: Set[str] = set()
_deprecations: FrozenSet[str] = frozenset(["get_dtype_counts", "get_values", "ix"])
_deprecations: FrozenSet[str] = frozenset(["get_values", "ix"])
_metadata: List[str] = []
_is_copy = None
_data: BlockManager
Expand Down Expand Up @@ -1988,26 +1988,6 @@ def __array_wrap__(self, result, context=None):
# values = self.values
# return dict(typestr=values.dtype.str,shape=values.shape,data=values)

def to_dense(self):
"""
Return dense representation of Series/DataFrame (as opposed to sparse).

.. deprecated:: 0.25.0

Returns
-------
%(klass)s
Dense %(klass)s.
"""
warnings.warn(
"DataFrame/Series.to_dense is deprecated "
"and will be removed in a future version",
FutureWarning,
stacklevel=2,
)
# compat
return self

# ----------------------------------------------------------------------
# Picklability

Expand Down Expand Up @@ -5520,51 +5500,6 @@ def get_values(self):
def _internal_get_values(self):
return self.values

def get_dtype_counts(self):
"""
Return counts of unique dtypes in this object.

.. deprecated:: 0.25.0

Use `.dtypes.value_counts()` instead.

Returns
-------
dtype : Series
Series with the count of columns with each dtype.

See Also
--------
dtypes : Return the dtypes 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_dtype_counts()
float64 1
int64 1
object 1
dtype: int64
"""
warnings.warn(
"`get_dtype_counts` has been deprecated and will be "
"removed in a future version. For DataFrames use "
"`.dtypes.value_counts()",
FutureWarning,
stacklevel=2,
)

from pandas import Series

return Series(self._data.get_dtype_counts())

@property
def dtypes(self):
"""
Expand Down
17 changes: 1 addition & 16 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Index(IndexOpsMixin, PandasObject):
_deprecations: FrozenSet[str] = (
PandasObject._deprecations
| IndexOpsMixin._deprecations
| frozenset(["asobject", "contains", "dtype_str", "get_values", "set_value"])
| frozenset(["contains", "get_values", "set_value"])
)

# To hand over control to subclasses
Expand Down Expand Up @@ -670,21 +670,6 @@ def dtype(self):
"""
return self._data.dtype

@property
def dtype_str(self):
"""
Return the dtype str of the underlying data.

.. deprecated:: 0.25.0
"""
warnings.warn(
"`dtype_str` has been deprecated. Call `str` on the "
"dtype attribute instead.",
FutureWarning,
stacklevel=2,
)
return str(self.dtype)

def ravel(self, order="C"):
"""
Return an ndarray of the flattened values of the underlying data.
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ class TestConstructors(base.BaseConstructorsTests):


class TestReshaping(base.BaseReshapingTests):
def test_ravel(self, data):
# GH#27199 Categorical.ravel returns self until after deprecation cycle
with tm.assert_produces_warning(FutureWarning):
data.ravel()
pass


class TestGetitem(base.BaseGetitemTests):
Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,23 +950,3 @@ def test_axis_classmethods(self, box):
assert obj._get_axis_number(v) == box._get_axis_number(v)
assert obj._get_axis_name(v) == box._get_axis_name(v)
assert obj._get_block_manager_axis(v) == box._get_block_manager_axis(v)

def test_deprecated_to_dense(self):
# GH 26557: DEPR
# Deprecated 0.25.0

df = pd.DataFrame({"A": [1, 2, 3]})
with tm.assert_produces_warning(FutureWarning):
result = df.to_dense()
tm.assert_frame_equal(result, df)

ser = pd.Series([1, 2, 3])
with tm.assert_produces_warning(FutureWarning):
result = ser.to_dense()
tm.assert_series_equal(result, ser)

def test_deprecated_get_dtype_counts(self):
# GH 18262
df = DataFrame([1])
with tm.assert_produces_warning(FutureWarning):
df.get_dtype_counts()
7 changes: 0 additions & 7 deletions pandas/tests/indexes/multi/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
import pandas.util.testing as tm


def test_dtype_str(indices):
with tm.assert_produces_warning(FutureWarning):
dtype = indices.dtype_str
assert isinstance(dtype, str)
assert dtype == str(indices.dtype)


def test_format(idx):
idx.format()
idx[:0].format()
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ def test_shallow_copy_changing_freq_raises(self):
with pytest.raises(IncompatibleFrequency, match=msg):
pi._shallow_copy(pi, freq="H")

def test_dtype_str(self):
pi = pd.PeriodIndex([], freq="M")
with tm.assert_produces_warning(FutureWarning):
assert pi.dtype_str == "period[M]"
assert pi.dtype_str == str(pi.dtype)

with tm.assert_produces_warning(FutureWarning):
pi = pd.PeriodIndex([], freq="3M")
assert pi.dtype_str == "period[3M]"
assert pi.dtype_str == str(pi.dtype)

def test_view_asi8(self):
idx = pd.PeriodIndex([], freq="M")

Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ def test_set_name_methods(self, indices):
assert indices.name == name
assert indices.names == [name]

def test_dtype_str(self, indices):
with tm.assert_produces_warning(FutureWarning):
dtype = indices.dtype_str
assert isinstance(dtype, str)
assert dtype == str(indices.dtype)

def test_hash_error(self, indices):
index = indices
with pytest.raises(
Expand Down