From 2a828b5f970f778483633ed3b67ff621bc627a7c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 09:23:21 -0800 Subject: [PATCH 1/5] port 29891 --- pandas/io/pytables.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 69d632479e969..a50d2d1a72155 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2641,7 +2641,9 @@ def write(self, **kwargs): "cannot write on an abstract storer: sublcasses should implement" ) - def delete(self, where=None, start=None, stop=None, **kwargs): + def delete( + self, where=None, start: Optional[int] = None, stop: Optional[int] = None + ): """ support fully deleting the node in its entirety (only) - where specification must be None From 3a6cc44f615d78f39280dc40e72385c17fac1a39 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 09:31:21 -0800 Subject: [PATCH 2/5] DEPR: dtype_str, to_dense --- doc/redirects.csv | 1 - doc/source/reference/indexing.rst | 1 - doc/source/whatsnew/v1.0.0.rst | 2 ++ pandas/core/generic.py | 20 -------------------- pandas/core/indexes/base.py | 17 +---------------- pandas/tests/indexes/multi/test_format.py | 7 ------- pandas/tests/indexes/period/test_period.py | 11 ----------- pandas/tests/indexes/test_common.py | 6 ------ 8 files changed, 3 insertions(+), 62 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index fb922eb79e363..68f3696eeeaf3 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -635,7 +635,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 diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index 448f020cfa56f..e8bc192d7cf93 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/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index db23bfdc8a5bd..1e8f08dff0b6d 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -453,6 +453,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`) - 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`) +- 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`) - .. _whatsnew_1000.performance: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2e2ae4e1dfa0a..fb182c55d83ad 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1990,26 +1990,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 diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 486cc0cd9032d..ace5182c698c2 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/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( From 5bdaa22044d98d30707582ec1c462ce4376c6bc6 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 11:49:19 -0800 Subject: [PATCH 3/5] DEPR: Categorical.ravel, get_dtype_counts --- asv_bench/benchmarks/frame_methods.py | 2 +- doc/redirects.csv | 6 --- doc/source/reference/frame.rst | 1 - doc/source/whatsnew/v1.0.0.rst | 2 + pandas/core/arrays/categorical.py | 19 ++++----- pandas/core/generic.py | 49 +--------------------- pandas/tests/extension/test_categorical.py | 5 +-- pandas/tests/generic/test_generic.py | 20 --------- 8 files changed, 14 insertions(+), 90 deletions(-) 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 68f3696eeeaf3..497bfd58de594 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -359,8 +359,6 @@ generated/pandas.DataFrame.from_items,../reference/api/pandas.DataFrame.from_ite generated/pandas.DataFrame.from_records,../reference/api/pandas.DataFrame.from_records generated/pandas.DataFrame.ftypes,../reference/api/pandas.DataFrame.ftypes 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_ftype_counts,../reference/api/pandas.DataFrame.get_ftype_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 @@ -884,8 +882,6 @@ generated/pandas.Panel.from_dict,../reference/api/pandas.Panel.from_dict generated/pandas.Panel.fromDict,../reference/api/pandas.Panel.fromDict generated/pandas.Panel.ftypes,../reference/api/pandas.Panel.ftypes generated/pandas.Panel.ge,../reference/api/pandas.Panel.ge -generated/pandas.Panel.get_dtype_counts,../reference/api/pandas.Panel.get_dtype_counts -generated/pandas.Panel.get_ftype_counts,../reference/api/pandas.Panel.get_ftype_counts generated/pandas.Panel.get,../reference/api/pandas.Panel.get generated/pandas.Panel.get_value,../reference/api/pandas.Panel.get_value generated/pandas.Panel.get_values,../reference/api/pandas.Panel.get_values @@ -1225,8 +1221,6 @@ generated/pandas.Series.from_csv,../reference/api/pandas.Series.from_csv generated/pandas.Series.ftype,../reference/api/pandas.Series.ftype generated/pandas.Series.ftypes,../reference/api/pandas.Series.ftypes 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_ftype_counts,../reference/api/pandas.Series.get_ftype_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 diff --git a/doc/source/reference/frame.rst b/doc/source/reference/frame.rst index 4540504974f56..beca379cf72b1 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -29,7 +29,6 @@ Attributes and underlying data DataFrame.dtypes DataFrame.ftypes - DataFrame.get_dtype_counts DataFrame.select_dtypes DataFrame.values DataFrame.get_values diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 1e8f08dff0b6d..3d5325286fcf7 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -455,6 +455,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - :func:`Series.expanding().apply() `, and :func:`DataFrame.expanding().apply() ` to ``False`` (:issue:`20584`) - 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`) - .. _whatsnew_1000.performance: diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 6cc3f660fb425..01fe439a4c743 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1709,23 +1709,22 @@ def _values_for_rank(self): ) return values - def ravel(self, order="C"): + def ravel(self, order: str = "C") -> "Categorical": """ - Return a flattened (numpy) array. + Return a view on self. For internal compatibility with numpy arrays. + Parameters + ---------- + order : str, default "C" + Parameter is ignored, is for compat with ndarray signature. + Returns ------- - numpy.array + Categorical """ - warn( - "Categorical.ravel will return a Categorical object instead " - "of an ndarray in a future version.", - FutureWarning, - stacklevel=2, - ) - return np.array(self) + return self.view() def view(self, dtype=None): if dtype is not None: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fb182c55d83ad..17b8bceb17d6d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -171,9 +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", "ftypes", "ix"] - ) + _deprecations: FrozenSet[str] = frozenset(["get_values", "ftypes", "ix"]) _metadata: List[str] = [] _is_copy = None _data: BlockManager @@ -5502,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/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() From 46f572522aebeeef38d01abd672a2ab15a5f8be7 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 12:23:24 -0800 Subject: [PATCH 4/5] fix docstring validation --- doc/redirects.csv | 3 --- doc/source/reference/frame.rst | 1 - doc/source/reference/series.rst | 1 - pandas/core/dtypes/common.py | 4 ---- 4 files changed, 9 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index 497bfd58de594..2b062404432ed 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -486,7 +486,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 @@ -973,7 +972,6 @@ generated/pandas.Panel.take,../reference/api/pandas.Panel.take generated/pandas.Panel.timetuple,../reference/api/pandas.Panel.timetuple generated/pandas.Panel.to_clipboard,../reference/api/pandas.Panel.to_clipboard generated/pandas.Panel.to_csv,../reference/api/pandas.Panel.to_csv -generated/pandas.Panel.to_dense,../reference/api/pandas.Panel.to_dense generated/pandas.Panel.to_excel,../reference/api/pandas.Panel.to_excel generated/pandas.Panel.to_frame,../reference/api/pandas.Panel.to_frame generated/pandas.Panel.to_hdf,../reference/api/pandas.Panel.to_hdf @@ -1411,7 +1409,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 beca379cf72b1..fa40570742028 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -363,7 +363,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/series.rst b/doc/source/reference/series.rst index c501e8bc91379..8855b3d745dc3 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -586,7 +586,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/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. From be5c8cac8ce7cefc931afcdbd86b83074520b324 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 29 Nov 2019 15:46:09 -0800 Subject: [PATCH 5/5] match other EA behavior --- pandas/core/arrays/categorical.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index d4471cedfbc00..4955d76f93d2d 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1696,23 +1696,6 @@ def _values_for_rank(self): ) return values - def ravel(self, order: str = "C") -> "Categorical": - """ - Return a view on self. - - For internal compatibility with numpy arrays. - - Parameters - ---------- - order : str, default "C" - Parameter is ignored, is for compat with ndarray signature. - - Returns - ------- - Categorical - """ - return self.view() - def view(self, dtype=None): if dtype is not None: raise NotImplementedError(dtype)