Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ Other Deprecations
- The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version (:issue:`26405`).
- The internal attributes ``_start``, ``_stop`` and ``_step`` attributes of :class:`RangeIndex` have been deprecated.
Use the public attributes :attr:`~RangeIndex.start`, :attr:`~RangeIndex.stop` and :attr:`~RangeIndex.step` instead (:issue:`26581`).
- The :meth:`Series.ftype`, :meth:`Series.ftypes` and :meth:`DataFrame.ftypes` methods are deprecated and will be removed in a future version.
Instead, use :meth:`Series.dtype`, :meth:`Series.dtypes` and :meth:`DataFrame.dtypes` (:issue:`26705`).


.. _whatsnew_0250.prior_deprecations:
Expand Down
8 changes: 8 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5525,6 +5525,9 @@ 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
Expand Down Expand Up @@ -5562,6 +5565,11 @@ def ftypes(self):
3 float64:sparse
dtype: object
"""
warnings.warn("ftypes is deprecated and will "
"be removed in a future version. "
"Use dtypes instead.",
FutureWarning, stacklevel=2)

from pandas import Series
return Series(self._data.get_ftypes(), index=self._info_axis,
dtype=np.object_)
Expand Down
16 changes: 16 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,30 @@ def dtypes(self):
def ftype(self):
"""
Return if the data is sparse|dense.

.. deprecated:: 0.25.0
Use :func:`dtype` instead.
"""
warnings.warn("ftype is deprecated and will "
"be removed in a future version. "
"Use 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("ftypes is deprecated and will "
"be removed in a future version. "
"Use dtypes instead.",
FutureWarning, stacklevel=2)

return self._data.ftype

@property
Expand Down
38 changes: 29 additions & 9 deletions pandas/tests/frame/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,34 @@ def test_concat_empty_dataframe_dtypes(self):
def test_empty_frame_dtypes_ftypes(self):
empty_df = pd.DataFrame()
assert_series_equal(empty_df.dtypes, pd.Series(dtype=np.object))
assert_series_equal(empty_df.ftypes, pd.Series(dtype=np.object))

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(empty_df.ftypes, pd.Series(dtype=np.object))

nocols_df = pd.DataFrame(index=[1, 2, 3])
assert_series_equal(nocols_df.dtypes, pd.Series(dtype=np.object))
assert_series_equal(nocols_df.ftypes, pd.Series(dtype=np.object))

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(nocols_df.ftypes, pd.Series(dtype=np.object))

norows_df = pd.DataFrame(columns=list("abc"))
assert_series_equal(norows_df.dtypes, pd.Series(
np.object, index=list("abc")))
assert_series_equal(norows_df.ftypes, pd.Series(
'object:dense', index=list("abc")))

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(norows_df.ftypes, pd.Series(
'object:dense', index=list("abc")))

norows_int_df = pd.DataFrame(columns=list("abc")).astype(np.int32)
assert_series_equal(norows_int_df.dtypes, pd.Series(
np.dtype('int32'), index=list("abc")))
assert_series_equal(norows_int_df.ftypes, pd.Series(
'int32:dense', index=list("abc")))
# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
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)]),
Expand All @@ -66,11 +77,17 @@ def test_empty_frame_dtypes_ftypes(self):
('b', 'bool:dense'),
('c', 'float64:dense')]))
assert_series_equal(df.dtypes, ex_dtypes)
assert_series_equal(df.ftypes, ex_ftypes)

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(df.ftypes, ex_ftypes)

# same but for empty slice of df
assert_series_equal(df[:0].dtypes, ex_dtypes)
assert_series_equal(df[:0].ftypes, ex_ftypes)

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(df[:0].ftypes, ex_ftypes)

def test_datetime_with_tz_dtypes(self):
tzframe = DataFrame({'A': date_range('20130101', periods=3),
Expand Down Expand Up @@ -402,7 +419,10 @@ def test_ftypes(self):
B='float32:dense',
C='float16:dense',
D='float64:dense')).sort_values()
result = frame.ftypes.sort_values()

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
result = frame.ftypes.sort_values()
assert_series_equal(result, expected)

def test_astype(self):
Expand Down
15 changes: 12 additions & 3 deletions pandas/tests/series/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,30 @@ def test_concat_empty_series_dtypes(self):
result = pd.concat([Series(dtype='float64').to_sparse(), Series(
dtype='float64').to_sparse()])
assert result.dtype == 'Sparse[float64]'
assert result.ftype == 'float64:sparse'

# GH 26705 - Assert .ftype is deprecated
with tm.assert_produces_warning(FutureWarning):
assert result.ftype == 'float64:sparse'

result = pd.concat([Series(dtype='float64').to_sparse(), Series(
dtype='float64')])
# TODO: release-note: concat sparse dtype
expected = pd.core.sparse.api.SparseDtype(np.float64)
assert result.dtype == expected
assert result.ftype == 'float64:sparse'

# GH 26705 - Assert .ftype is deprecated
with tm.assert_produces_warning(FutureWarning):
assert result.ftype == 'float64:sparse'

result = pd.concat([Series(dtype='float64').to_sparse(), Series(
dtype='object')])
# TODO: release-note: concat sparse dtype
expected = pd.core.sparse.api.SparseDtype('object')
assert result.dtype == expected
assert result.ftype == 'object:sparse'

# 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
10 changes: 8 additions & 2 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def test_dtype(self, datetime_series):

assert datetime_series.dtype == np.dtype('float64')
assert datetime_series.dtypes == np.dtype('float64')
assert datetime_series.ftype == 'float64:dense'
assert datetime_series.ftypes == 'float64:dense'

# 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'
tm.assert_series_equal(datetime_series.get_dtype_counts(),
Series(1, ['float64']))
# GH18243 - Assert .get_ftype_counts is deprecated
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/sparse/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def test_construct_DataFrame_with_sp_series(self):

# blocking
expected = Series({'col': 'float64:sparse'})
result = df.ftypes

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
result = df.ftypes
tm.assert_series_equal(expected, result)

def test_constructor_preserve_attr(self):
Expand Down