Skip to content

Commit 734b6d1

Browse files
authored
CLN: Remove cdate_range, raise_on_error keyword, categories and ordered keywords in astype (#27141)
* Remove raise_on_error * Removed categories and ordered keywords in astype * Remove cdate_range * Remove unused import
1 parent 0b90d5b commit 734b6d1

File tree

8 files changed

+13
-163
lines changed

8 files changed

+13
-163
lines changed

doc/source/user_guide/timeseries.rst

-10
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,6 @@ resulting ``DatetimeIndex``:
474474
Custom frequency ranges
475475
~~~~~~~~~~~~~~~~~~~~~~~
476476

477-
.. warning::
478-
479-
This functionality was originally exclusive to ``cdate_range``, which is
480-
deprecated as of version 0.21.0 in favor of ``bdate_range``. Note that
481-
``cdate_range`` only utilizes the ``weekmask`` and ``holidays`` parameters
482-
when custom business day, 'C', is passed as the frequency string. Support has
483-
been expanded with ``bdate_range`` to work with any custom frequency string.
484-
485-
.. versionadded:: 0.21.0
486-
487477
``bdate_range`` can also generate a range of custom frequency dates by using
488478
the ``weekmask`` and ``holidays`` parameters. These parameters will only be
489479
used if a custom frequency string is passed.

doc/source/whatsnew/v0.25.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ Removal of prior version deprecations/changes
637637
- Removed the previously deprecated behavior of altering column or index labels with :meth:`Series.rename_axis` or :meth:`DataFrame.rename_axis` (:issue:`17842`)
638638
- Removed the previously deprecated ``tupleize_cols`` keyword argument in :meth:`read_html`, :meth:`read_csv`, and :meth:`DataFrame.to_csv` (:issue:`17877`, :issue:`17820`)
639639
- Removed the previously deprecated ``DataFrame.from.csv`` and ``Series.from_csv`` (:issue:`17812`)
640+
- Removed the previously deprecated ``raise_on_error`` keyword argument in :meth:`DataFrame.where` and :meth:`DataFrame.mask` (:issue:`17744`)
641+
- Removed the previously deprecated ``ordered`` and ``categories`` keyword arguments in ``astype`` (:issue:`17742`)
642+
- Removed the previously deprecated ``cdate_range`` (:issue:`17691`)
640643

641644
.. _whatsnew_0250.performance:
642645

pandas/core/generic.py

+2-31
Original file line numberDiff line numberDiff line change
@@ -8644,13 +8644,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
86448644
86458645
try_cast : bool, default False
86468646
Try to cast the result back to the input type (if possible).
8647-
raise_on_error : bool, default True
8648-
Whether to raise on invalid data types (e.g. trying to where on
8649-
strings).
8650-
8651-
.. deprecated:: 0.21.0
8652-
8653-
Use `errors`.
86548647
86558648
Returns
86568649
-------
@@ -8738,18 +8731,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
87388731
cond_rev="False", name='where',
87398732
name_other='mask'))
87408733
def where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
8741-
errors='raise', try_cast=False, raise_on_error=None):
8742-
8743-
if raise_on_error is not None:
8744-
warnings.warn(
8745-
"raise_on_error is deprecated in "
8746-
"favor of errors='raise|ignore'",
8747-
FutureWarning, stacklevel=2)
8748-
8749-
if raise_on_error:
8750-
errors = 'raise'
8751-
else:
8752-
errors = 'ignore'
8734+
errors='raise', try_cast=False):
87538735

87548736
other = com.apply_if_callable(other, self)
87558737
return self._where(cond, other, inplace, axis, level,
@@ -8759,18 +8741,7 @@ def where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
87598741
cond_rev="True", name='mask',
87608742
name_other='where'))
87618743
def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
8762-
errors='raise', try_cast=False, raise_on_error=None):
8763-
8764-
if raise_on_error is not None:
8765-
warnings.warn(
8766-
"raise_on_error is deprecated in "
8767-
"favor of errors='raise|ignore'",
8768-
FutureWarning, stacklevel=2)
8769-
8770-
if raise_on_error:
8771-
errors = 'raise'
8772-
else:
8773-
errors = 'ignore'
8744+
errors='raise', try_cast=False):
87748745

87758746
inplace = validate_bool_kwarg(inplace, 'inplace')
87768747
cond = com.apply_if_callable(cond, self)

pandas/core/indexes/datetimes.py

+1-61
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import pandas.core.tools.datetimes as tools
3030

3131
from pandas.tseries.frequencies import Resolution, to_offset
32-
from pandas.tseries.offsets import CDay, Nano, prefix_mapping
32+
from pandas.tseries.offsets import Nano, prefix_mapping
3333

3434

3535
def _new_DatetimeIndex(cls, d):
@@ -1568,66 +1568,6 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
15681568
closed=closed, **kwargs)
15691569

15701570

1571-
def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
1572-
normalize=True, name=None, closed=None, **kwargs):
1573-
"""
1574-
Return a fixed frequency DatetimeIndex, with CustomBusinessDay as the
1575-
default frequency
1576-
1577-
.. deprecated:: 0.21.0
1578-
1579-
Parameters
1580-
----------
1581-
start : string or datetime-like, default None
1582-
Left bound for generating dates
1583-
end : string or datetime-like, default None
1584-
Right bound for generating dates
1585-
periods : integer, default None
1586-
Number of periods to generate
1587-
freq : string or DateOffset, default 'C' (CustomBusinessDay)
1588-
Frequency strings can have multiples, e.g. '5H'
1589-
tz : string, default None
1590-
Time zone name for returning localized DatetimeIndex, for example
1591-
Asia/Beijing
1592-
normalize : bool, default False
1593-
Normalize start/end dates to midnight before generating date range
1594-
name : string, default None
1595-
Name of the resulting DatetimeIndex
1596-
weekmask : string, Default 'Mon Tue Wed Thu Fri'
1597-
weekmask of valid business days, passed to ``numpy.busdaycalendar``
1598-
holidays : list
1599-
list/array of dates to exclude from the set of valid business days,
1600-
passed to ``numpy.busdaycalendar``
1601-
closed : string, default None
1602-
Make the interval closed with respect to the given frequency to
1603-
the 'left', 'right', or both sides (None)
1604-
1605-
Notes
1606-
-----
1607-
Of the three parameters: ``start``, ``end``, and ``periods``, exactly two
1608-
must be specified.
1609-
1610-
To learn more about the frequency strings, please see `this link
1611-
<http://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.
1612-
1613-
Returns
1614-
-------
1615-
rng : DatetimeIndex
1616-
"""
1617-
warnings.warn("cdate_range is deprecated and will be removed in a future "
1618-
"version, instead use pd.bdate_range(..., freq='{freq}')"
1619-
.format(freq=freq), FutureWarning, stacklevel=2)
1620-
1621-
if freq == 'C':
1622-
holidays = kwargs.pop('holidays', [])
1623-
weekmask = kwargs.pop('weekmask', 'Mon Tue Wed Thu Fri')
1624-
freq = CDay(holidays=holidays, weekmask=weekmask)
1625-
1626-
return date_range(start=start, end=end, periods=periods, freq=freq,
1627-
tz=tz, normalize=normalize, name=name,
1628-
closed=closed, **kwargs)
1629-
1630-
16311571
def _time_to_micros(time):
16321572
seconds = time.hour * 60 * 60 + 60 * time.minute + time.second
16331573
return 1000000 * seconds + time.microsecond

pandas/core/internals/blocks.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,10 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
542542
if self.is_categorical_astype(dtype):
543543

544544
# deprecated 17636
545-
if ('categories' in kwargs or 'ordered' in kwargs):
546-
if isinstance(dtype, CategoricalDtype):
547-
raise TypeError(
548-
"Cannot specify a CategoricalDtype and also "
549-
"`categories` or `ordered`. Use "
550-
"`dtype=CategoricalDtype(categories, ordered)`"
551-
" instead.")
552-
warnings.warn("specifying 'categories' or 'ordered' in "
553-
".astype() is deprecated; pass a "
554-
"CategoricalDtype instead",
555-
FutureWarning, stacklevel=7)
545+
for deprecated_arg in ('categories', 'ordered'):
546+
if deprecated_arg in kwargs:
547+
raise ValueError('Got an unexpected argument: {}'.format(
548+
deprecated_arg))
556549

557550
categories = kwargs.get('categories', None)
558551
ordered = kwargs.get('ordered', None)

pandas/tests/api/test_api.py

-10
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,3 @@ def test_testing(self):
131131

132132
from pandas import testing
133133
self.check(testing, self.funcs)
134-
135-
136-
class TestCDateRange:
137-
138-
def test_deprecation_cdaterange(self):
139-
# GH17596
140-
from pandas.core.indexes.datetimes import cdate_range
141-
with tm.assert_produces_warning(FutureWarning,
142-
check_stacklevel=False):
143-
cdate_range('2017-01-01', '2017-12-31')

pandas/tests/series/indexing/test_boolean.py

-11
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,6 @@ def test_where_unsafe():
229229
assert_series_equal(result, expected)
230230

231231

232-
def test_where_raise_on_error_deprecation():
233-
# gh-14968
234-
# deprecation of raise_on_error
235-
s = Series(np.random.randn(5))
236-
cond = s > 0
237-
with tm.assert_produces_warning(FutureWarning):
238-
s.where(cond, raise_on_error=True)
239-
with tm.assert_produces_warning(FutureWarning):
240-
s.mask(cond, raise_on_error=True)
241-
242-
243232
def test_where():
244233
s = Series(np.random.randn(5))
245234
cond = s > 0

pandas/tests/series/test_dtypes.py

+3-29
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,12 @@ def test_astype_dict_like(self, dtype_class):
223223
with pytest.raises(KeyError, match=msg):
224224
s.astype(dt5)
225225

226-
def test_astype_categories_deprecation(self):
226+
def test_astype_categories_deprecation_raises(self):
227227

228228
# deprecated 17636
229229
s = Series(['a', 'b', 'a'])
230-
expected = s.astype(CategoricalDtype(['a', 'b'], ordered=True))
231-
with tm.assert_produces_warning(FutureWarning,
232-
check_stacklevel=False):
233-
result = s.astype('category', categories=['a', 'b'], ordered=True)
234-
tm.assert_series_equal(result, expected)
230+
with pytest.raises(ValueError, match="Got an unexpected"):
231+
s.astype('category', categories=['a', 'b'], ordered=True)
235232

236233
def test_astype_from_categorical(self):
237234
items = ["a", "b", "c", "a"]
@@ -349,21 +346,12 @@ def test_astype_categorical_to_categorical(self, name, dtype_ordered,
349346
expected = Series(s_data, name=name, dtype=exp_dtype)
350347
tm.assert_series_equal(result, expected)
351348

352-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
353-
result = s.astype('category', ordered=dtype_ordered)
354-
tm.assert_series_equal(result, expected)
355-
356349
# different categories
357350
dtype = CategoricalDtype(list('adc'), dtype_ordered)
358351
result = s.astype(dtype)
359352
expected = Series(s_data, name=name, dtype=dtype)
360353
tm.assert_series_equal(result, expected)
361354

362-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
363-
result = s.astype(
364-
'category', categories=list('adc'), ordered=dtype_ordered)
365-
tm.assert_series_equal(result, expected)
366-
367355
if dtype_ordered is False:
368356
# not specifying ordered, so only test once
369357
expected = s
@@ -387,20 +375,6 @@ def test_astype_categoricaldtype(self):
387375
tm.assert_series_equal(result, expected)
388376
tm.assert_index_equal(result.cat.categories, Index(['a', 'b', 'c']))
389377

390-
def test_astype_categoricaldtype_with_args(self):
391-
s = Series(['a', 'b'])
392-
type_ = CategoricalDtype(['a', 'b'])
393-
394-
msg = (r"Cannot specify a CategoricalDtype and also `categories` or"
395-
r" `ordered`\. Use `dtype=CategoricalDtype\(categories,"
396-
r" ordered\)` instead\.")
397-
with pytest.raises(TypeError, match=msg):
398-
s.astype(type_, ordered=True)
399-
with pytest.raises(TypeError, match=msg):
400-
s.astype(type_, categories=['a', 'b'])
401-
with pytest.raises(TypeError, match=msg):
402-
s.astype(type_, categories=['a', 'b'], ordered=False)
403-
404378
@pytest.mark.parametrize("dtype", [
405379
np.datetime64,
406380
np.timedelta64,

0 commit comments

Comments
 (0)