From ab64dd72e1aedac49d552d01ff3a0dcf18868178 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 12:49:09 -0800 Subject: [PATCH] DEPR: ftype, ftypes (#29895) --- doc/redirects.csv | 7 --- doc/source/reference/frame.rst | 1 - doc/source/reference/series.rst | 2 - doc/source/whatsnew/v1.0.0.rst | 1 + pandas/core/generic.py | 57 +--------------------- pandas/core/internals/managers.py | 12 ----- pandas/core/series.py | 40 +-------------- pandas/tests/frame/test_dtypes.py | 48 +----------------- pandas/tests/series/test_combine_concat.py | 12 ----- pandas/tests/series/test_dtypes.py | 8 --- 10 files changed, 4 insertions(+), 184 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index fb922eb79e363..f124fdb840ce0 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -357,10 +357,8 @@ generated/pandas.DataFrame.from_csv,../reference/api/pandas.DataFrame.from_csv 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.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 @@ -883,10 +881,8 @@ generated/pandas.Panel.first_valid_index,../reference/api/pandas.Panel.first_val generated/pandas.Panel.floordiv,../reference/api/pandas.Panel.floordiv 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 @@ -1223,11 +1219,8 @@ generated/pandas.Series.flags,../reference/api/pandas.Series.flags 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.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..5c860f2d4cb03 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.ftypes DataFrame.get_dtype_counts DataFrame.select_dtypes DataFrame.values diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index c501e8bc91379..528cc8a0c3920 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -29,7 +29,6 @@ Attributes Series.array Series.values Series.dtype - Series.ftype Series.shape Series.nbytes Series.ndim @@ -43,7 +42,6 @@ Attributes Series.flags Series.empty Series.dtypes - Series.ftypes Series.data Series.name Series.put diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 8ac1a235951b8..eaa2b860e6a58 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -440,6 +440,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed the previously deprecated :meth:`Series.valid`; use :meth:`Series.dropna` instead (:issue:`18800`) - Removed the previously properties :attr:`DataFrame.is_copy`, :attr:`Series.is_copy` (:issue:`18812`) - Removed the previously deprecated :meth:`DataFrame.get_ftype_counts`, :meth:`Series.get_ftype_counts` (:issue:`18243`) +- Removed the previously deprecated :meth:`DataFrame.ftypes`, :meth:`Series.ftypes`, :meth:`Series.ftype` (:issue:`26744`) - Removed the previously deprecated :meth:`Index.get_duplicated`, use ``idx[idx.duplicated()].unique()`` instead (:issue:`20239`) - Removed the previously deprecated :meth:`Series.clip_upper`, :meth:`Series.clip_lower`, :meth:`DataFrame.clip_upper`, :meth:`DataFrame.clip_lower` (:issue:`24203`) - Removed the ability to alter :attr:`DatetimeIndex.freq`, :attr:`TimedeltaIndex.freq`, or :attr:`PeriodIndex.freq` (:issue:`20772`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 046a9082e942e..29eeb5999b88f 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_dtype_counts", "get_values", "ix"]) _metadata: List[str] = [] _is_copy = None _data: BlockManager @@ -5582,10 +5580,6 @@ def dtypes(self): pandas.Series The data type of each column. - See Also - -------- - DataFrame.ftypes : Dtype and sparsity information. - Examples -------- >>> df = pd.DataFrame({'float': [1.0], @@ -5603,55 +5597,6 @@ def dtypes(self): return Series(self._data.get_dtypes(), index=self._info_axis, dtype=np.object_) - @property - def ftypes(self): - """ - Return the ftypes (indication of sparse/dense and dtype) in DataFrame. - - .. deprecated:: 0.25.0 - Use :func:`dtypes` instead. - - This returns a Series with the data type of each column. - The result's index is the original DataFrame's columns. Columns - with mixed types are stored with the ``object`` dtype. See - :ref:`the User Guide ` for more. - - Returns - ------- - pandas.Series - The data type and indication of sparse/dense of each column. - - See Also - -------- - DataFrame.dtypes: Series with just dtype information. - - Notes - ----- - Sparse data should have the same dtypes as its dense representation. - - Examples - -------- - >>> arr = np.random.RandomState(0).randn(100, 4) - >>> arr[arr < .8] = np.nan - >>> pd.DataFrame(arr).ftypes - 0 float64:dense - 1 float64:dense - 2 float64:dense - 3 float64:dense - dtype: object - """ - warnings.warn( - "DataFrame.ftypes is deprecated and will " - "be removed in a future version. " - "Use DataFrame.dtypes instead.", - FutureWarning, - stacklevel=2, - ) - - from pandas import Series - - return Series(self._data.get_ftypes(), index=self._info_axis, dtype=np.object_) - def _to_dict_of_blocks(self, copy=True): """ Return a dict of dtype -> Constructor Types that diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index c37a8ea5e42a4..19901dc510199 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -82,7 +82,6 @@ class BlockManager(PandasObject): get_dtype_counts get_dtypes - get_ftypes apply(func, axes, block_filter_fn) @@ -251,10 +250,6 @@ def get_dtypes(self): dtypes = np.array([blk.dtype for blk in self.blocks]) return algos.take_1d(dtypes, self._blknos, allow_fill=False) - def get_ftypes(self): - ftypes = np.array([blk.ftype for blk in self.blocks]) - return algos.take_1d(ftypes, self._blknos, allow_fill=False) - def __getstate__(self): block_values = [b.values for b in self.blocks] block_items = [self.items[b.mgr_locs.indexer] for b in self.blocks] @@ -1546,19 +1541,12 @@ def dtype(self): def array_dtype(self): return self._block.array_dtype - @property - def ftype(self): - return self._block.ftype - def get_dtype_counts(self): return {self.dtype.name: 1} def get_dtypes(self): return np.array([self._block.dtype]) - def get_ftypes(self): - return np.array([self._block.ftype]) - def external_values(self): return self._block.external_values() diff --git a/pandas/core/series.py b/pandas/core/series.py index a9ecf97dad68b..dd1f3b1a9d3f3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -158,9 +158,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _deprecations = ( base.IndexOpsMixin._deprecations | generic.NDFrame._deprecations - | frozenset( - ["compress", "valid", "ftype", "real", "imag", "put", "ptp", "nonzero"] - ) + | frozenset(["compress", "valid", "real", "imag", "put", "ptp", "nonzero"]) ) # Override cache_readonly bc Series is mutable @@ -418,42 +416,6 @@ def name(self, value: Optional[Hashable]) -> None: raise TypeError("Series.name must be a hashable type") self.attrs["name"] = value - @property - def ftype(self): - """ - Return if the data is sparse|dense. - - .. deprecated:: 0.25.0 - Use :func:`dtype` instead. - """ - warnings.warn( - "Series.ftype is deprecated and will " - "be removed in a future version. " - "Use Series.dtype instead.", - FutureWarning, - stacklevel=2, - ) - - return self._data.ftype - - @property - def ftypes(self): - """ - Return if the data is sparse|dense. - - .. deprecated:: 0.25.0 - Use :func:`dtypes` instead. - """ - warnings.warn( - "Series.ftypes is deprecated and will " - "be removed in a future version. " - "Use Series.dtype instead.", - FutureWarning, - stacklevel=2, - ) - - return self._data.ftype - @property def values(self): """ diff --git a/pandas/tests/frame/test_dtypes.py b/pandas/tests/frame/test_dtypes.py index cdcd5996324da..af5a765aa2729 100644 --- a/pandas/tests/frame/test_dtypes.py +++ b/pandas/tests/frame/test_dtypes.py @@ -46,63 +46,33 @@ def test_concat_empty_dataframe_dtypes(self): assert result["b"].dtype == np.float64 assert result["c"].dtype == np.float64 - def test_empty_frame_dtypes_ftypes(self): + def test_empty_frame_dtypes(self): empty_df = pd.DataFrame() tm.assert_series_equal(empty_df.dtypes, pd.Series(dtype=np.object)) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal(empty_df.ftypes, pd.Series(dtype=np.object)) - nocols_df = pd.DataFrame(index=[1, 2, 3]) tm.assert_series_equal(nocols_df.dtypes, pd.Series(dtype=np.object)) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal(nocols_df.ftypes, pd.Series(dtype=np.object)) - norows_df = pd.DataFrame(columns=list("abc")) tm.assert_series_equal( norows_df.dtypes, pd.Series(np.object, index=list("abc")) ) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal( - norows_df.ftypes, pd.Series("object:dense", index=list("abc")) - ) - norows_int_df = pd.DataFrame(columns=list("abc")).astype(np.int32) tm.assert_series_equal( norows_int_df.dtypes, pd.Series(np.dtype("int32"), index=list("abc")) ) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal( - norows_int_df.ftypes, pd.Series("int32:dense", index=list("abc")) - ) odict = OrderedDict df = pd.DataFrame(odict([("a", 1), ("b", True), ("c", 1.0)]), index=[1, 2, 3]) ex_dtypes = pd.Series( odict([("a", np.int64), ("b", np.bool), ("c", np.float64)]) ) - ex_ftypes = pd.Series( - odict([("a", "int64:dense"), ("b", "bool:dense"), ("c", "float64:dense")]) - ) tm.assert_series_equal(df.dtypes, ex_dtypes) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal(df.ftypes, ex_ftypes) - # same but for empty slice of df tm.assert_series_equal(df[:0].dtypes, ex_dtypes) - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - tm.assert_series_equal(df[:0].ftypes, ex_ftypes) - def test_datetime_with_tz_dtypes(self): tzframe = DataFrame( { @@ -474,22 +444,6 @@ def test_dtypes_gh8722(self, float_string_frame): result = df.dtypes tm.assert_series_equal(result, Series({0: np.dtype("int64")})) - def test_ftypes(self, mixed_float_frame): - frame = mixed_float_frame - expected = Series( - dict( - A="float32:dense", - B="float32:dense", - C="float16:dense", - D="float64:dense", - ) - ).sort_values() - - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - result = frame.ftypes.sort_values() - tm.assert_series_equal(result, expected) - def test_astype_float(self, float_frame): casted = float_frame.astype(int) expected = DataFrame( diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index b2ecd7c4997f1..9d02c1bdc2d9c 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -290,10 +290,6 @@ def test_concat_empty_series_dtypes(self): ) assert result.dtype == "Sparse[float64]" - # GH 26705 - Assert .ftype is deprecated - with tm.assert_produces_warning(FutureWarning): - assert result.ftype == "float64:sparse" - result = pd.concat( [Series(dtype="float64").astype("Sparse"), Series(dtype="float64")] ) @@ -301,10 +297,6 @@ def test_concat_empty_series_dtypes(self): expected = pd.SparseDtype(np.float64) assert result.dtype == expected - # GH 26705 - Assert .ftype is deprecated - with tm.assert_produces_warning(FutureWarning): - assert result.ftype == "float64:sparse" - result = pd.concat( [Series(dtype="float64").astype("Sparse"), Series(dtype="object")] ) @@ -312,10 +304,6 @@ def test_concat_empty_series_dtypes(self): expected = pd.SparseDtype("object") assert result.dtype == expected - # GH 26705 - Assert .ftype is deprecated - with tm.assert_produces_warning(FutureWarning): - assert result.ftype == "object:sparse" - def test_combine_first_dt64(self): from pandas.core.tools.datetimes import to_datetime diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index ec0318b2af13a..0dc64651e8d58 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -49,14 +49,6 @@ def test_dtype(self, datetime_series): assert datetime_series.dtype == np.dtype("float64") assert datetime_series.dtypes == np.dtype("float64") - # GH 26705 - Assert .ftype is deprecated - with tm.assert_produces_warning(FutureWarning): - assert datetime_series.ftype == "float64:dense" - - # GH 26705 - Assert .ftypes is deprecated - with tm.assert_produces_warning(FutureWarning): - assert datetime_series.ftypes == "float64:dense" - @pytest.mark.parametrize("value", [np.nan, np.inf]) @pytest.mark.parametrize("dtype", [np.int32, np.int64]) def test_astype_cast_nan_inf_int(self, dtype, value):