Skip to content

Commit

Permalink
DEPR: ftype, ftypes (#29895)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Nov 27, 2019
1 parent 2b358a6 commit ab64dd7
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 184 deletions.
7 changes: 0 additions & 7 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 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.ftypes
DataFrame.get_dtype_counts
DataFrame.select_dtypes
DataFrame.values
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Attributes
Series.array
Series.values
Series.dtype
Series.ftype
Series.shape
Series.nbytes
Series.ndim
Expand All @@ -43,7 +42,6 @@ Attributes
Series.flags
Series.empty
Series.dtypes
Series.ftypes
Series.data
Series.name
Series.put
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
57 changes: 1 addition & 56 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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 <basics.dtypes>` 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
Expand Down
12 changes: 0 additions & 12 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class BlockManager(PandasObject):
get_dtype_counts
get_dtypes
get_ftypes
apply(func, axes, block_filter_fn)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()

Expand Down
40 changes: 1 addition & 39 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
48 changes: 1 addition & 47 deletions pandas/tests/frame/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/series/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,32 +290,20 @@ 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")]
)
# TODO: release-note: concat sparse dtype
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")]
)
# TODO: release-note: concat sparse dtype
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

Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ab64dd7

Please sign in to comment.