Skip to content

Commit 157a4e3

Browse files
thiviyanTjreback
authored andcommitted
Deprecated Series.ftype, Series.ftypes and DataFrame.ftypes features (#26744)
1 parent 16e8ea8 commit 157a4e3

File tree

7 files changed

+79
-15
lines changed

7 files changed

+79
-15
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ Other Deprecations
493493
- The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version (:issue:`26405`).
494494
- The internal attributes ``_start``, ``_stop`` and ``_step`` attributes of :class:`RangeIndex` have been deprecated.
495495
Use the public attributes :attr:`~RangeIndex.start`, :attr:`~RangeIndex.stop` and :attr:`~RangeIndex.step` instead (:issue:`26581`).
496+
- The :meth:`Series.ftype`, :meth:`Series.ftypes` and :meth:`DataFrame.ftypes` methods are deprecated and will be removed in a future version.
497+
Instead, use :meth:`Series.dtype` and :meth:`DataFrame.dtypes` (:issue:`26705`).
496498

497499

498500
.. _whatsnew_0250.prior_deprecations:

pandas/core/generic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5487,6 +5487,9 @@ def ftypes(self):
54875487
"""
54885488
Return the ftypes (indication of sparse/dense and dtype) in DataFrame.
54895489
5490+
.. deprecated:: 0.25.0
5491+
Use :func:`dtypes` instead.
5492+
54905493
This returns a Series with the data type of each column.
54915494
The result's index is the original DataFrame's columns. Columns
54925495
with mixed types are stored with the ``object`` dtype. See
@@ -5524,6 +5527,11 @@ def ftypes(self):
55245527
3 float64:sparse
55255528
dtype: object
55265529
"""
5530+
warnings.warn("DataFrame.ftypes is deprecated and will "
5531+
"be removed in a future version. "
5532+
"Use DataFrame.dtypes instead.",
5533+
FutureWarning, stacklevel=2)
5534+
55275535
from pandas import Series
55285536
return Series(self._data.get_ftypes(), index=self._info_axis,
55295537
dtype=np.object_)

pandas/core/series.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,30 @@ def dtypes(self):
419419
def ftype(self):
420420
"""
421421
Return if the data is sparse|dense.
422+
423+
.. deprecated:: 0.25.0
424+
Use :func:`dtype` instead.
422425
"""
426+
warnings.warn("Series.ftype is deprecated and will "
427+
"be removed in a future version. "
428+
"Use Series.dtype instead.",
429+
FutureWarning, stacklevel=2)
430+
423431
return self._data.ftype
424432

425433
@property
426434
def ftypes(self):
427435
"""
428436
Return if the data is sparse|dense.
437+
438+
.. deprecated:: 0.25.0
439+
Use :func:`dtypes` instead.
429440
"""
441+
warnings.warn("Series.ftypes is deprecated and will "
442+
"be removed in a future version. "
443+
"Use Series.dtype instead.",
444+
FutureWarning, stacklevel=2)
445+
430446
return self._data.ftype
431447

432448
@property

pandas/tests/frame/test_dtypes.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,34 @@ def test_concat_empty_dataframe_dtypes(self):
3838
def test_empty_frame_dtypes_ftypes(self):
3939
empty_df = pd.DataFrame()
4040
assert_series_equal(empty_df.dtypes, pd.Series(dtype=np.object))
41-
assert_series_equal(empty_df.ftypes, pd.Series(dtype=np.object))
41+
42+
# GH 26705 - Assert .ftypes is deprecated
43+
with tm.assert_produces_warning(FutureWarning):
44+
assert_series_equal(empty_df.ftypes, pd.Series(dtype=np.object))
4245

4346
nocols_df = pd.DataFrame(index=[1, 2, 3])
4447
assert_series_equal(nocols_df.dtypes, pd.Series(dtype=np.object))
45-
assert_series_equal(nocols_df.ftypes, pd.Series(dtype=np.object))
48+
49+
# GH 26705 - Assert .ftypes is deprecated
50+
with tm.assert_produces_warning(FutureWarning):
51+
assert_series_equal(nocols_df.ftypes, pd.Series(dtype=np.object))
4652

4753
norows_df = pd.DataFrame(columns=list("abc"))
4854
assert_series_equal(norows_df.dtypes, pd.Series(
4955
np.object, index=list("abc")))
50-
assert_series_equal(norows_df.ftypes, pd.Series(
51-
'object:dense', index=list("abc")))
56+
57+
# GH 26705 - Assert .ftypes is deprecated
58+
with tm.assert_produces_warning(FutureWarning):
59+
assert_series_equal(norows_df.ftypes, pd.Series(
60+
'object:dense', index=list("abc")))
5261

5362
norows_int_df = pd.DataFrame(columns=list("abc")).astype(np.int32)
5463
assert_series_equal(norows_int_df.dtypes, pd.Series(
5564
np.dtype('int32'), index=list("abc")))
56-
assert_series_equal(norows_int_df.ftypes, pd.Series(
57-
'int32:dense', index=list("abc")))
65+
# GH 26705 - Assert .ftypes is deprecated
66+
with tm.assert_produces_warning(FutureWarning):
67+
assert_series_equal(norows_int_df.ftypes, pd.Series(
68+
'int32:dense', index=list("abc")))
5869

5970
odict = OrderedDict
6071
df = pd.DataFrame(odict([('a', 1), ('b', True), ('c', 1.0)]),
@@ -66,11 +77,17 @@ def test_empty_frame_dtypes_ftypes(self):
6677
('b', 'bool:dense'),
6778
('c', 'float64:dense')]))
6879
assert_series_equal(df.dtypes, ex_dtypes)
69-
assert_series_equal(df.ftypes, ex_ftypes)
80+
81+
# GH 26705 - Assert .ftypes is deprecated
82+
with tm.assert_produces_warning(FutureWarning):
83+
assert_series_equal(df.ftypes, ex_ftypes)
7084

7185
# same but for empty slice of df
7286
assert_series_equal(df[:0].dtypes, ex_dtypes)
73-
assert_series_equal(df[:0].ftypes, ex_ftypes)
87+
88+
# GH 26705 - Assert .ftypes is deprecated
89+
with tm.assert_produces_warning(FutureWarning):
90+
assert_series_equal(df[:0].ftypes, ex_ftypes)
7491

7592
def test_datetime_with_tz_dtypes(self):
7693
tzframe = DataFrame({'A': date_range('20130101', periods=3),
@@ -402,7 +419,10 @@ def test_ftypes(self):
402419
B='float32:dense',
403420
C='float16:dense',
404421
D='float64:dense')).sort_values()
405-
result = frame.ftypes.sort_values()
422+
423+
# GH 26705 - Assert .ftypes is deprecated
424+
with tm.assert_produces_warning(FutureWarning):
425+
result = frame.ftypes.sort_values()
406426
assert_series_equal(result, expected)
407427

408428
def test_astype(self):

pandas/tests/series/test_combine_concat.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,30 @@ def test_concat_empty_series_dtypes(self):
247247
result = pd.concat([Series(dtype='float64').to_sparse(), Series(
248248
dtype='float64').to_sparse()])
249249
assert result.dtype == 'Sparse[float64]'
250-
assert result.ftype == 'float64:sparse'
250+
251+
# GH 26705 - Assert .ftype is deprecated
252+
with tm.assert_produces_warning(FutureWarning):
253+
assert result.ftype == 'float64:sparse'
251254

252255
result = pd.concat([Series(dtype='float64').to_sparse(), Series(
253256
dtype='float64')])
254257
# TODO: release-note: concat sparse dtype
255258
expected = pd.core.sparse.api.SparseDtype(np.float64)
256259
assert result.dtype == expected
257-
assert result.ftype == 'float64:sparse'
260+
261+
# GH 26705 - Assert .ftype is deprecated
262+
with tm.assert_produces_warning(FutureWarning):
263+
assert result.ftype == 'float64:sparse'
258264

259265
result = pd.concat([Series(dtype='float64').to_sparse(), Series(
260266
dtype='object')])
261267
# TODO: release-note: concat sparse dtype
262268
expected = pd.core.sparse.api.SparseDtype('object')
263269
assert result.dtype == expected
264-
assert result.ftype == 'object:sparse'
270+
271+
# GH 26705 - Assert .ftype is deprecated
272+
with tm.assert_produces_warning(FutureWarning):
273+
assert result.ftype == 'object:sparse'
265274

266275
def test_combine_first_dt64(self):
267276
from pandas.core.tools.datetimes import to_datetime

pandas/tests/series/test_dtypes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ def test_dtype(self, datetime_series):
4848

4949
assert datetime_series.dtype == np.dtype('float64')
5050
assert datetime_series.dtypes == np.dtype('float64')
51-
assert datetime_series.ftype == 'float64:dense'
52-
assert datetime_series.ftypes == 'float64:dense'
51+
52+
# GH 26705 - Assert .ftype is deprecated
53+
with tm.assert_produces_warning(FutureWarning):
54+
assert datetime_series.ftype == 'float64:dense'
55+
56+
# GH 26705 - Assert .ftypes is deprecated
57+
with tm.assert_produces_warning(FutureWarning):
58+
assert datetime_series.ftypes == 'float64:dense'
5359
tm.assert_series_equal(datetime_series.get_dtype_counts(),
5460
Series(1, ['float64']))
5561
# GH18243 - Assert .get_ftype_counts is deprecated

pandas/tests/sparse/series/test_series.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ def test_construct_DataFrame_with_sp_series(self):
164164

165165
# blocking
166166
expected = Series({'col': 'float64:sparse'})
167-
result = df.ftypes
167+
168+
# GH 26705 - Assert .ftypes is deprecated
169+
with tm.assert_produces_warning(FutureWarning):
170+
result = df.ftypes
168171
tm.assert_series_equal(expected, result)
169172

170173
def test_constructor_preserve_attr(self):

0 commit comments

Comments
 (0)