diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index eb9a0e83271f1..9647693d4ed6b 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -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() diff --git a/doc/redirects.csv b/doc/redirects.csv index 46021d052679f..4d171bc3d400d 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/doc/source/reference/frame.rst b/doc/source/reference/frame.rst index 5c860f2d4cb03..2604af4e33a89 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -28,7 +28,6 @@ Attributes and underlying data :toctree: api/ DataFrame.dtypes - DataFrame.get_dtype_counts DataFrame.select_dtypes DataFrame.values DataFrame.get_values @@ -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 diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index 8edea28c17318..c155b5e3fcb37 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -32,7 +32,6 @@ Properties Index.has_duplicates Index.hasnans Index.dtype - Index.dtype_str Index.inferred_type Index.is_all_dates Index.shape diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index 91843c7975a2c..2485b94ab4d09 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -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 diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 3f8d9d3916797..7d3f61ccf4e9f 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -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() `, :func:`DataFrame.rolling().apply() `, - :func:`Series.expanding().apply() `, and :func:`DataFrame.expanding().apply() ` to ``False`` (:issue:`20584`) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index ec1f5d2d6214c..0dc972011833a 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index d981a1d6e4aa4..43810df18b0aa 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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. diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b13aee238efb3..42b8214e07d49 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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 @@ -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 @@ -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): """ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4a3fa26c3460e..c2352c94f1316 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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 @@ -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. diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 528053aa8c7f1..dff1e58641ade 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -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): diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index c180511e31619..0912a8901dc6a 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -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() diff --git a/pandas/tests/indexes/multi/test_format.py b/pandas/tests/indexes/multi/test_format.py index a7f58b9ea78bd..3a8063aed8d20 100644 --- a/pandas/tests/indexes/multi/test_format.py +++ b/pandas/tests/indexes/multi/test_format.py @@ -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() diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index d75bd7bb21827..a07a87080804f 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -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") diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 558ba04b657a1..9e60b91db5e18 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -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(