diff --git a/doc/source/whatsnew/v0.15.0.rst b/doc/source/whatsnew/v0.15.0.rst index c27ada6ef3b58..b328e549e8899 100644 --- a/doc/source/whatsnew/v0.15.0.rst +++ b/doc/source/whatsnew/v0.15.0.rst @@ -312,14 +312,13 @@ Timezone handling improvements previously this resulted in ``Exception`` or ``TypeError`` (:issue:`7812`) .. ipython:: python - :okwarning: ts = pd.Timestamp('2014-08-01 09:00', tz='US/Eastern') ts ts.tz_localize(None) - didx = pd.DatetimeIndex(start='2014-08-01 09:00', freq='H', - periods=10, tz='US/Eastern') + didx = pd.date_range(start='2014-08-01 09:00', freq='H', + periods=10, tz='US/Eastern') didx didx.tz_localize(None) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 4e8a471239610..6c25f0cd30666 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -421,6 +421,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`) - :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`) - :meth:`Series.where` with ``Categorical`` dtype (or :meth:`DataFrame.where` with ``Categorical`` column) no longer allows setting new categories (:issue:`24114`) +- :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` constructors no longer allow ``start``, ``end``, and ``periods`` keywords, use :func:`date_range`, :func:`timedelta_range`, and :func:`period_range` instead (:issue:`23919`) +- :class:`DatetimeIndex` and :class:`TimedeltaIndex` constructors no longer have a ``verify_integrity`` keyword argument (:issue:`23919`) - :func:`core.internals.blocks.make_block` no longer accepts the "fastpath" keyword(:issue:`19265`) - :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword(:issue:`19434`) - Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 0d368845ea4f2..cef8155f0bfa3 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -54,11 +54,10 @@ def _new_DatetimeIndex(cls, d): result = cls._simple_new(data, **d) else: with warnings.catch_warnings(): - # we ignore warnings from passing verify_integrity=False # TODO: If we knew what was going in to **d, we might be able to # go through _simple_new instead warnings.simplefilter("ignore") - result = cls.__new__(cls, verify_integrity=False, **d) + result = cls.__new__(cls, **d) return result @@ -263,9 +262,6 @@ def __new__( cls, data=None, freq=None, - start=None, - end=None, - periods=None, tz=None, normalize=False, closed=None, @@ -275,39 +271,8 @@ def __new__( dtype=None, copy=False, name=None, - verify_integrity=None, ): - if verify_integrity is not None: - warnings.warn( - "The 'verify_integrity' argument is deprecated, " - "will be removed in a future version.", - FutureWarning, - stacklevel=2, - ) - else: - verify_integrity = True - - if data is None: - dtarr = DatetimeArray._generate_range( - start, - end, - periods, - freq=freq, - tz=tz, - normalize=normalize, - closed=closed, - ambiguous=ambiguous, - ) - warnings.warn( - "Creating a DatetimeIndex by passing range " - "endpoints is deprecated. Use " - "`pandas.date_range` instead.", - FutureWarning, - stacklevel=2, - ) - return cls._simple_new(dtarr._data, freq=dtarr.freq, tz=dtarr.tz, name=name) - if is_scalar(data): raise TypeError( "{cls}() must be called with a " diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index b3476dcb12abd..d63de10d92921 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -187,9 +187,6 @@ def __new__( data=None, ordinal=None, freq=None, - start=None, - end=None, - periods=None, tz=None, dtype=None, copy=False, @@ -219,29 +216,9 @@ def __new__( if data is None and ordinal is None: # range-based. - data, freq2 = PeriodArray._generate_range(start, end, periods, freq, fields) - # PeriodArray._generate range does validate that fields is + data, freq2 = PeriodArray._generate_range(None, None, None, freq, fields) + # PeriodArray._generate range does validation that fields is # empty when really using the range-based constructor. - if not fields: - msg = ( - "Creating a PeriodIndex by passing range " - "endpoints is deprecated. Use " - "`pandas.period_range` instead." - ) - # period_range differs from PeriodIndex for cases like - # start="2000", periods=4 - # PeriodIndex interprets that as A-DEC freq. - # period_range interprets it as 'D' freq. - cond = freq is None and ( - (start and not isinstance(start, Period)) - or (end and not isinstance(end, Period)) - ) - if cond: - msg += ( - " Note that the default `freq` may differ. Pass " - "'freq=\"{}\"' to ensure the same output." - ).format(freq2.freqstr) - warnings.warn(msg, FutureWarning, stacklevel=2) freq = freq2 data = PeriodArray(data, freq=freq) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 7a7720f730312..57cb170dc0ae8 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -186,40 +186,12 @@ def __new__( data=None, unit=None, freq=None, - start=None, - end=None, - periods=None, closed=None, dtype=_TD_DTYPE, copy=False, name=None, - verify_integrity=None, ): - if verify_integrity is not None: - warnings.warn( - "The 'verify_integrity' argument is deprecated, " - "will be removed in a future version.", - FutureWarning, - stacklevel=2, - ) - else: - verify_integrity = True - - if data is None: - freq, freq_infer = dtl.maybe_infer_freq(freq) - warnings.warn( - "Creating a TimedeltaIndex by passing range " - "endpoints is deprecated. Use " - "`pandas.timedelta_range` instead.", - FutureWarning, - stacklevel=2, - ) - result = TimedeltaArray._generate_range( - start, end, periods, freq, closed=closed - ) - return cls._simple_new(result._data, freq=freq, name=name) - if is_scalar(data): raise TypeError( "{cls}() must be called with a " diff --git a/pandas/tests/indexes/datetimes/test_construction.py b/pandas/tests/indexes/datetimes/test_construction.py index 4ef1cbd5af958..88290bf31ba9d 100644 --- a/pandas/tests/indexes/datetimes/test_construction.py +++ b/pandas/tests/indexes/datetimes/test_construction.py @@ -485,16 +485,6 @@ def test_construction_with_ndarray(self): expected = DatetimeIndex(["2013-10-07", "2013-10-08", "2013-10-09"], freq="B") tm.assert_index_equal(result, expected) - def test_verify_integrity_deprecated(self): - # GH#23919 - with tm.assert_produces_warning(FutureWarning): - DatetimeIndex(["1/1/2000"], verify_integrity=False) - - def test_range_kwargs_deprecated(self): - # GH#23919 - with tm.assert_produces_warning(FutureWarning): - DatetimeIndex(start="1/1/2000", end="1/10/2000", freq="D") - def test_integer_values_and_tz_deprecated(self): # GH-24559 values = np.array([946684800000000000]) @@ -517,10 +507,6 @@ def test_constructor_coverage(self): with pytest.raises(TypeError, match=msg): date_range(start="1/1/2000", periods="foo", freq="D") - with pytest.raises(ValueError): - with tm.assert_produces_warning(FutureWarning): - DatetimeIndex(start="1/1/2000", end="1/10/2000") - with pytest.raises(TypeError): DatetimeIndex("1/1/2000") diff --git a/pandas/tests/indexes/period/test_construction.py b/pandas/tests/indexes/period/test_construction.py index 1973cb7f4740d..2adce0b7f8b44 100644 --- a/pandas/tests/indexes/period/test_construction.py +++ b/pandas/tests/indexes/period/test_construction.py @@ -35,10 +35,7 @@ def test_construction_base_constructor(self): def test_constructor_use_start_freq(self): # GH #1118 p = Period("4/2/2012", freq="B") - with tm.assert_produces_warning(FutureWarning): - index = PeriodIndex(start=p, periods=10) expected = period_range(start="4/2/2012", periods=10, freq="B") - tm.assert_index_equal(index, expected) index = period_range(start=p, periods=10) tm.assert_index_equal(index, expected) @@ -68,12 +65,6 @@ def test_constructor_field_arrays(self): with pytest.raises(ValueError, match=msg): PeriodIndex(year=years, month=months, freq="2M") - msg = "Can either instantiate from fields or endpoints, but not both" - with pytest.raises(ValueError, match=msg): - PeriodIndex( - year=years, month=months, freq="M", start=Period("2007-01", freq="M") - ) - years = [2007, 2007, 2007] months = [1, 2, 3] idx = PeriodIndex(year=years, month=months, freq="M") @@ -115,26 +106,6 @@ def test_constructor_invalid_quarters(self): PeriodIndex(year=range(2000, 2004), quarter=list(range(4)), freq="Q-DEC") def test_constructor_corner(self): - msg = "Not enough parameters to construct Period range" - with pytest.raises(ValueError, match=msg): - PeriodIndex(periods=10, freq="A") - - start = Period("2007", freq="A-JUN") - end = Period("2010", freq="A-DEC") - - msg = "start and end must have same freq" - with pytest.raises(ValueError, match=msg): - PeriodIndex(start=start, end=end) - - msg = ( - "Of the three parameters: start, end, and periods, exactly two" - " must be specified" - ) - with pytest.raises(ValueError, match=msg): - PeriodIndex(start=start) - with pytest.raises(ValueError, match=msg): - PeriodIndex(end=end) - result = period_range("2007-01", periods=10.5, freq="M") exp = period_range("2007-01", periods=10, freq="M") tm.assert_index_equal(result, exp) @@ -368,27 +339,20 @@ def test_constructor_year_and_quarter(self): p = PeriodIndex(lops) tm.assert_index_equal(p, idx) - @pytest.mark.parametrize( - "func, warning", [(PeriodIndex, FutureWarning), (period_range, None)] - ) - def test_constructor_freq_mult(self, func, warning): + def test_constructor_freq_mult(self): # GH #7811 - with tm.assert_produces_warning(warning): - # must be the same, but for sure... - pidx = func(start="2014-01", freq="2M", periods=4) + pidx = period_range(start="2014-01", freq="2M", periods=4) expected = PeriodIndex(["2014-01", "2014-03", "2014-05", "2014-07"], freq="2M") tm.assert_index_equal(pidx, expected) - with tm.assert_produces_warning(warning): - pidx = func(start="2014-01-02", end="2014-01-15", freq="3D") + pidx = period_range(start="2014-01-02", end="2014-01-15", freq="3D") expected = PeriodIndex( ["2014-01-02", "2014-01-05", "2014-01-08", "2014-01-11", "2014-01-14"], freq="3D", ) tm.assert_index_equal(pidx, expected) - with tm.assert_produces_warning(warning): - pidx = func(end="2014-01-01 17:00", freq="4H", periods=3) + pidx = period_range(end="2014-01-01 17:00", freq="4H", periods=3) expected = PeriodIndex( ["2014-01-01 09:00", "2014-01-01 13:00", "2014-01-01 17:00"], freq="4H" ) @@ -425,18 +389,6 @@ def test_constructor_freq_combined(self): expected = PeriodIndex(["2016-01-01 00:00", "2016-01-02 01:00"], freq="25H") tm.assert_index_equal(pidx, expected) - def test_constructor_range_based_deprecated(self): - with tm.assert_produces_warning(FutureWarning): - pi = PeriodIndex(freq="A", start="1/1/2001", end="12/1/2009") - assert len(pi) == 9 - - def test_constructor_range_based_deprecated_different_freq(self): - with tm.assert_produces_warning(FutureWarning) as m: - PeriodIndex(start="2000", periods=2) - - (warning,) = m - assert 'freq="A-DEC"' in str(warning.message) - def test_constructor(self): pi = period_range(freq="A", start="1/1/2001", end="12/1/2009") assert len(pi) == 9 @@ -507,21 +459,6 @@ def test_constructor(self): with pytest.raises(IncompatibleFrequency, match=msg): PeriodIndex(vals) - def test_constructor_error(self): - start = Period("02-Apr-2005", "B") - end_intv = Period("2006-12-31", ("w", 1)) - - msg = "start and end must have same freq" - with pytest.raises(ValueError, match=msg): - PeriodIndex(start=start, end=end_intv) - - msg = ( - "Of the three parameters: start, end, and periods, " - "exactly two must be specified" - ) - with pytest.raises(ValueError, match=msg): - PeriodIndex(start=start) - @pytest.mark.parametrize( "freq", ["M", "Q", "A", "D", "B", "T", "S", "L", "U", "N", "H"] ) diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index a07a87080804f..14bf6490a706b 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -529,15 +529,10 @@ def test_pindex_qaccess(self): assert s["05Q4"] == s[2] def test_pindex_multiples(self): - with tm.assert_produces_warning(FutureWarning): - pi = PeriodIndex(start="1/1/11", end="12/31/11", freq="2M") expected = PeriodIndex( ["2011-01", "2011-03", "2011-05", "2011-07", "2011-09", "2011-11"], freq="2M", ) - tm.assert_index_equal(pi, expected) - assert pi.freq == offsets.MonthEnd(2) - assert pi.freqstr == "2M" pi = period_range(start="1/1/11", end="12/31/11", freq="2M") tm.assert_index_equal(pi, expected) diff --git a/pandas/tests/indexes/timedeltas/test_construction.py b/pandas/tests/indexes/timedeltas/test_construction.py index 3cf86bea1d6de..c8feb9e2a853a 100644 --- a/pandas/tests/indexes/timedeltas/test_construction.py +++ b/pandas/tests/indexes/timedeltas/test_construction.py @@ -10,16 +10,6 @@ class TestTimedeltaIndex: - def test_verify_integrity_deprecated(self): - # GH#23919 - with tm.assert_produces_warning(FutureWarning): - TimedeltaIndex(["1 Day"], verify_integrity=False) - - def test_range_kwargs_deprecated(self): - # GH#23919 - with tm.assert_produces_warning(FutureWarning): - TimedeltaIndex(start="1 Day", end="3 Days", freq="D") - def test_int64_nocopy(self): # GH#23539 check that a copy isn't made when we pass int64 data # and copy=False @@ -166,10 +156,6 @@ def test_constructor_coverage(self): with pytest.raises(TypeError, match=msg): timedelta_range(start="1 days", periods="foo", freq="D") - with pytest.raises(ValueError): - with tm.assert_produces_warning(FutureWarning): - TimedeltaIndex(start="1 days", end="10 days") - with pytest.raises(TypeError): TimedeltaIndex("1 days")