Skip to content

Commit c849121

Browse files
jorisvandenbosscheAndrew Bui
authored and
Andrew Bui
committed
CLN: remove deprecated infer_dst keyword (pandas-dev#20490)
1 parent 2d6e76c commit c849121

File tree

7 files changed

+10
-33
lines changed

7 files changed

+10
-33
lines changed

asv_bench/benchmarks/timeseries.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def setup(self):
7575
freq='S'))
7676

7777
def time_infer_dst(self):
78-
with warnings.catch_warnings(record=True):
79-
self.index.tz_localize('US/Eastern', infer_dst=True)
78+
self.index.tz_localize('US/Eastern', ambiguous='infer')
8079

8180

8281
class ResetIndex(object):

doc/source/timeseries.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -2191,10 +2191,9 @@ Ambiguous Times when Localizing
21912191

21922192
In some cases, localize cannot determine the DST and non-DST hours when there are
21932193
duplicates. This often happens when reading files or database records that simply
2194-
duplicate the hours. Passing ``ambiguous='infer'`` (``infer_dst`` argument in prior
2195-
releases) into ``tz_localize`` will attempt to determine the right offset. Below
2196-
the top example will fail as it contains ambiguous times and the bottom will
2197-
infer the right offset.
2194+
duplicate the hours. Passing ``ambiguous='infer'`` into ``tz_localize`` will
2195+
attempt to determine the right offset. Below the top example will fail as it
2196+
contains ambiguous times and the bottom will infer the right offset.
21982197

21992198
.. ipython:: python
22002199

doc/source/whatsnew/v0.23.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ Removal of prior version deprecations/changes
778778
- The top-level functions ``pd.rolling_*``, ``pd.expanding_*`` and ``pd.ewm*`` have been removed (Deprecated since v0.18).
779779
Instead, use the DataFrame/Series methods :attr:`~DataFrame.rolling`, :attr:`~DataFrame.expanding` and :attr:`~DataFrame.ewm` (:issue:`18723`)
780780
- Imports from ``pandas.core.common`` for functions such as ``is_datetime64_dtype`` are now removed. These are located in ``pandas.api.types``. (:issue:`13634`, :issue:`19769`)
781+
- The ``infer_dst`` keyword in :meth:`Series.tz_localize`, :meth:`DatetimeIndex.tz_localize`
782+
and :class:`DatetimeIndex` have been removed. ``infer_dst=True`` is equivalent to
783+
``ambiguous='infer'``, and ``infer_dst=False`` to ``ambiguous='raise'`` (:issue:`7963`).
784+
781785

782786
.. _whatsnew_0230.performance:
783787

pandas/core/generic.py

-6
Original file line numberDiff line numberDiff line change
@@ -7937,9 +7937,6 @@ def _tz_convert(ax, tz):
79377937
result.set_axis(ax, axis=axis, inplace=True)
79387938
return result.__finalize__(self)
79397939

7940-
@deprecate_kwarg(old_arg_name='infer_dst', new_arg_name='ambiguous',
7941-
mapping={True: 'infer',
7942-
False: 'raise'})
79437940
def tz_localize(self, tz, axis=0, level=None, copy=True,
79447941
ambiguous='raise'):
79457942
"""
@@ -7963,9 +7960,6 @@ def tz_localize(self, tz, axis=0, level=None, copy=True,
79637960
- 'NaT' will return NaT where there are ambiguous times
79647961
- 'raise' will raise an AmbiguousTimeError if there are ambiguous
79657962
times
7966-
infer_dst : boolean, default False
7967-
.. deprecated:: 0.15.0
7968-
Attempt to infer fall dst-transition hours based on order
79697963
79707964
Returns
79717965
-------

pandas/core/indexes/datetimes.py

-11
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
208208
times)
209209
- 'NaT' will return NaT where there are ambiguous times
210210
- 'raise' will raise an AmbiguousTimeError if there are ambiguous times
211-
infer_dst : boolean, default False
212-
.. deprecated:: 0.15.0
213-
Attempt to infer fall dst-transition hours based on order
214211
name : object
215212
Name to be stored in the index
216213
dayfirst : bool, default False
@@ -329,8 +326,6 @@ def _add_comparison_methods(cls):
329326
_is_numeric_dtype = False
330327
_infer_as_myclass = True
331328

332-
@deprecate_kwarg(old_arg_name='infer_dst', new_arg_name='ambiguous',
333-
mapping={True: 'infer', False: 'raise'})
334329
def __new__(cls, data=None,
335330
freq=None, start=None, end=None, periods=None, tz=None,
336331
normalize=False, closed=None, ambiguous='raise',
@@ -2270,8 +2265,6 @@ def tz_convert(self, tz):
22702265
# No conversion since timestamps are all UTC to begin with
22712266
return self._shallow_copy(tz=tz)
22722267

2273-
@deprecate_kwarg(old_arg_name='infer_dst', new_arg_name='ambiguous',
2274-
mapping={True: 'infer', False: 'raise'})
22752268
def tz_localize(self, tz, ambiguous='raise', errors='raise'):
22762269
"""
22772270
Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex.
@@ -2306,10 +2299,6 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
23062299
23072300
.. versionadded:: 0.19.0
23082301
2309-
infer_dst : boolean, default False
2310-
.. deprecated:: 0.15.0
2311-
Attempt to infer fall dst-transition hours based on order
2312-
23132302
Returns
23142303
-------
23152304
DatetimeIndex

pandas/core/indexes/period.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def tz_convert(self, tz):
10951095
"""
10961096
raise NotImplementedError("Not yet implemented for PeriodIndex")
10971097

1098-
def tz_localize(self, tz, infer_dst=False):
1098+
def tz_localize(self, tz, ambiguous='raise'):
10991099
"""
11001100
Localize tz-naive DatetimeIndex to given time zone (using
11011101
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex
@@ -1106,8 +1106,6 @@ def tz_localize(self, tz, infer_dst=False):
11061106
Time zone for time. Corresponding timestamps would be converted to
11071107
time zone of the TimeSeries.
11081108
None will remove timezone holding local time.
1109-
infer_dst : boolean, default False
1110-
Attempt to infer fall dst-transition hours based on order
11111109
11121110
Returns
11131111
-------

pandas/tests/indexes/datetimes/test_timezones.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,6 @@ def test_dti_tz_localize_ambiguous_infer(self, tz):
341341
di = DatetimeIndex(times)
342342
localized = di.tz_localize(tz, ambiguous='infer')
343343
tm.assert_index_equal(dr, localized)
344-
with tm.assert_produces_warning(FutureWarning):
345-
localized_old = di.tz_localize(tz, infer_dst=True)
346-
tm.assert_index_equal(dr, localized_old)
347344
tm.assert_index_equal(dr, DatetimeIndex(times, tz=tz,
348345
ambiguous='infer'))
349346

@@ -353,9 +350,6 @@ def test_dti_tz_localize_ambiguous_infer(self, tz):
353350
localized = dr.tz_localize(tz)
354351
localized_infer = dr.tz_localize(tz, ambiguous='infer')
355352
tm.assert_index_equal(localized, localized_infer)
356-
with tm.assert_produces_warning(FutureWarning):
357-
localized_infer_old = dr.tz_localize(tz, infer_dst=True)
358-
tm.assert_index_equal(localized, localized_infer_old)
359353

360354
@pytest.mark.parametrize('tz', [pytz.timezone('US/Eastern'),
361355
gettz('US/Eastern')])
@@ -525,7 +519,7 @@ def test_dti_tz_localize_ambiguous_flags(self, tz):
525519
localized = DatetimeIndex(times, tz=tz, ambiguous=is_dst)
526520
tm.assert_index_equal(dr, localized)
527521

528-
# Test duplicate times where infer_dst fails
522+
# Test duplicate times where inferring the dst fails
529523
times += times
530524
di = DatetimeIndex(times)
531525

0 commit comments

Comments
 (0)