Skip to content

Commit 7e791e4

Browse files
jbrockmendeljreback
authored andcommitted
DEPR: DTI/TDI/PI constructor arguments (#29930)
1 parent 9b02d54 commit 7e791e4

File tree

9 files changed

+11
-192
lines changed

9 files changed

+11
-192
lines changed

doc/source/whatsnew/v0.15.0.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,13 @@ Timezone handling improvements
312312
previously this resulted in ``Exception`` or ``TypeError`` (:issue:`7812`)
313313

314314
.. ipython:: python
315-
:okwarning:
316315
317316
ts = pd.Timestamp('2014-08-01 09:00', tz='US/Eastern')
318317
ts
319318
ts.tz_localize(None)
320319
321-
didx = pd.DatetimeIndex(start='2014-08-01 09:00', freq='H',
322-
periods=10, tz='US/Eastern')
320+
didx = pd.date_range(start='2014-08-01 09:00', freq='H',
321+
periods=10, tz='US/Eastern')
323322
didx
324323
didx.tz_localize(None)
325324

doc/source/whatsnew/v1.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
465465
- :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`)
466466
- :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`)
467467
- :meth:`Series.where` with ``Categorical`` dtype (or :meth:`DataFrame.where` with ``Categorical`` column) no longer allows setting new categories (:issue:`24114`)
468+
- :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`)
469+
- :class:`DatetimeIndex` and :class:`TimedeltaIndex` constructors no longer have a ``verify_integrity`` keyword argument (:issue:`23919`)
468470
- :func:`core.internals.blocks.make_block` no longer accepts the "fastpath" keyword(:issue:`19265`)
469471
- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword(:issue:`19434`)
470472
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)

pandas/core/indexes/datetimes.py

+1-36
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ def _new_DatetimeIndex(cls, d):
5454
result = cls._simple_new(data, **d)
5555
else:
5656
with warnings.catch_warnings():
57-
# we ignore warnings from passing verify_integrity=False
5857
# TODO: If we knew what was going in to **d, we might be able to
5958
# go through _simple_new instead
6059
warnings.simplefilter("ignore")
61-
result = cls.__new__(cls, verify_integrity=False, **d)
60+
result = cls.__new__(cls, **d)
6261

6362
return result
6463

@@ -263,9 +262,6 @@ def __new__(
263262
cls,
264263
data=None,
265264
freq=None,
266-
start=None,
267-
end=None,
268-
periods=None,
269265
tz=None,
270266
normalize=False,
271267
closed=None,
@@ -275,39 +271,8 @@ def __new__(
275271
dtype=None,
276272
copy=False,
277273
name=None,
278-
verify_integrity=None,
279274
):
280275

281-
if verify_integrity is not None:
282-
warnings.warn(
283-
"The 'verify_integrity' argument is deprecated, "
284-
"will be removed in a future version.",
285-
FutureWarning,
286-
stacklevel=2,
287-
)
288-
else:
289-
verify_integrity = True
290-
291-
if data is None:
292-
dtarr = DatetimeArray._generate_range(
293-
start,
294-
end,
295-
periods,
296-
freq=freq,
297-
tz=tz,
298-
normalize=normalize,
299-
closed=closed,
300-
ambiguous=ambiguous,
301-
)
302-
warnings.warn(
303-
"Creating a DatetimeIndex by passing range "
304-
"endpoints is deprecated. Use "
305-
"`pandas.date_range` instead.",
306-
FutureWarning,
307-
stacklevel=2,
308-
)
309-
return cls._simple_new(dtarr._data, freq=dtarr.freq, tz=dtarr.tz, name=name)
310-
311276
if is_scalar(data):
312277
raise TypeError(
313278
"{cls}() must be called with a "

pandas/core/indexes/period.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ def __new__(
187187
data=None,
188188
ordinal=None,
189189
freq=None,
190-
start=None,
191-
end=None,
192-
periods=None,
193190
tz=None,
194191
dtype=None,
195192
copy=False,
@@ -219,29 +216,9 @@ def __new__(
219216

220217
if data is None and ordinal is None:
221218
# range-based.
222-
data, freq2 = PeriodArray._generate_range(start, end, periods, freq, fields)
223-
# PeriodArray._generate range does validate that fields is
219+
data, freq2 = PeriodArray._generate_range(None, None, None, freq, fields)
220+
# PeriodArray._generate range does validation that fields is
224221
# empty when really using the range-based constructor.
225-
if not fields:
226-
msg = (
227-
"Creating a PeriodIndex by passing range "
228-
"endpoints is deprecated. Use "
229-
"`pandas.period_range` instead."
230-
)
231-
# period_range differs from PeriodIndex for cases like
232-
# start="2000", periods=4
233-
# PeriodIndex interprets that as A-DEC freq.
234-
# period_range interprets it as 'D' freq.
235-
cond = freq is None and (
236-
(start and not isinstance(start, Period))
237-
or (end and not isinstance(end, Period))
238-
)
239-
if cond:
240-
msg += (
241-
" Note that the default `freq` may differ. Pass "
242-
"'freq=\"{}\"' to ensure the same output."
243-
).format(freq2.freqstr)
244-
warnings.warn(msg, FutureWarning, stacklevel=2)
245222
freq = freq2
246223

247224
data = PeriodArray(data, freq=freq)

pandas/core/indexes/timedeltas.py

-28
Original file line numberDiff line numberDiff line change
@@ -186,40 +186,12 @@ def __new__(
186186
data=None,
187187
unit=None,
188188
freq=None,
189-
start=None,
190-
end=None,
191-
periods=None,
192189
closed=None,
193190
dtype=_TD_DTYPE,
194191
copy=False,
195192
name=None,
196-
verify_integrity=None,
197193
):
198194

199-
if verify_integrity is not None:
200-
warnings.warn(
201-
"The 'verify_integrity' argument is deprecated, "
202-
"will be removed in a future version.",
203-
FutureWarning,
204-
stacklevel=2,
205-
)
206-
else:
207-
verify_integrity = True
208-
209-
if data is None:
210-
freq, freq_infer = dtl.maybe_infer_freq(freq)
211-
warnings.warn(
212-
"Creating a TimedeltaIndex by passing range "
213-
"endpoints is deprecated. Use "
214-
"`pandas.timedelta_range` instead.",
215-
FutureWarning,
216-
stacklevel=2,
217-
)
218-
result = TimedeltaArray._generate_range(
219-
start, end, periods, freq, closed=closed
220-
)
221-
return cls._simple_new(result._data, freq=freq, name=name)
222-
223195
if is_scalar(data):
224196
raise TypeError(
225197
"{cls}() must be called with a "

pandas/tests/indexes/datetimes/test_construction.py

-14
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,6 @@ def test_construction_with_ndarray(self):
485485
expected = DatetimeIndex(["2013-10-07", "2013-10-08", "2013-10-09"], freq="B")
486486
tm.assert_index_equal(result, expected)
487487

488-
def test_verify_integrity_deprecated(self):
489-
# GH#23919
490-
with tm.assert_produces_warning(FutureWarning):
491-
DatetimeIndex(["1/1/2000"], verify_integrity=False)
492-
493-
def test_range_kwargs_deprecated(self):
494-
# GH#23919
495-
with tm.assert_produces_warning(FutureWarning):
496-
DatetimeIndex(start="1/1/2000", end="1/10/2000", freq="D")
497-
498488
def test_integer_values_and_tz_deprecated(self):
499489
# GH-24559
500490
values = np.array([946684800000000000])
@@ -517,10 +507,6 @@ def test_constructor_coverage(self):
517507
with pytest.raises(TypeError, match=msg):
518508
date_range(start="1/1/2000", periods="foo", freq="D")
519509

520-
with pytest.raises(ValueError):
521-
with tm.assert_produces_warning(FutureWarning):
522-
DatetimeIndex(start="1/1/2000", end="1/10/2000")
523-
524510
with pytest.raises(TypeError):
525511
DatetimeIndex("1/1/2000")
526512

pandas/tests/indexes/period/test_construction.py

+4-67
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ def test_construction_base_constructor(self):
3535
def test_constructor_use_start_freq(self):
3636
# GH #1118
3737
p = Period("4/2/2012", freq="B")
38-
with tm.assert_produces_warning(FutureWarning):
39-
index = PeriodIndex(start=p, periods=10)
4038
expected = period_range(start="4/2/2012", periods=10, freq="B")
41-
tm.assert_index_equal(index, expected)
4239

4340
index = period_range(start=p, periods=10)
4441
tm.assert_index_equal(index, expected)
@@ -68,12 +65,6 @@ def test_constructor_field_arrays(self):
6865
with pytest.raises(ValueError, match=msg):
6966
PeriodIndex(year=years, month=months, freq="2M")
7067

71-
msg = "Can either instantiate from fields or endpoints, but not both"
72-
with pytest.raises(ValueError, match=msg):
73-
PeriodIndex(
74-
year=years, month=months, freq="M", start=Period("2007-01", freq="M")
75-
)
76-
7768
years = [2007, 2007, 2007]
7869
months = [1, 2, 3]
7970
idx = PeriodIndex(year=years, month=months, freq="M")
@@ -115,26 +106,6 @@ def test_constructor_invalid_quarters(self):
115106
PeriodIndex(year=range(2000, 2004), quarter=list(range(4)), freq="Q-DEC")
116107

117108
def test_constructor_corner(self):
118-
msg = "Not enough parameters to construct Period range"
119-
with pytest.raises(ValueError, match=msg):
120-
PeriodIndex(periods=10, freq="A")
121-
122-
start = Period("2007", freq="A-JUN")
123-
end = Period("2010", freq="A-DEC")
124-
125-
msg = "start and end must have same freq"
126-
with pytest.raises(ValueError, match=msg):
127-
PeriodIndex(start=start, end=end)
128-
129-
msg = (
130-
"Of the three parameters: start, end, and periods, exactly two"
131-
" must be specified"
132-
)
133-
with pytest.raises(ValueError, match=msg):
134-
PeriodIndex(start=start)
135-
with pytest.raises(ValueError, match=msg):
136-
PeriodIndex(end=end)
137-
138109
result = period_range("2007-01", periods=10.5, freq="M")
139110
exp = period_range("2007-01", periods=10, freq="M")
140111
tm.assert_index_equal(result, exp)
@@ -368,27 +339,20 @@ def test_constructor_year_and_quarter(self):
368339
p = PeriodIndex(lops)
369340
tm.assert_index_equal(p, idx)
370341

371-
@pytest.mark.parametrize(
372-
"func, warning", [(PeriodIndex, FutureWarning), (period_range, None)]
373-
)
374-
def test_constructor_freq_mult(self, func, warning):
342+
def test_constructor_freq_mult(self):
375343
# GH #7811
376-
with tm.assert_produces_warning(warning):
377-
# must be the same, but for sure...
378-
pidx = func(start="2014-01", freq="2M", periods=4)
344+
pidx = period_range(start="2014-01", freq="2M", periods=4)
379345
expected = PeriodIndex(["2014-01", "2014-03", "2014-05", "2014-07"], freq="2M")
380346
tm.assert_index_equal(pidx, expected)
381347

382-
with tm.assert_produces_warning(warning):
383-
pidx = func(start="2014-01-02", end="2014-01-15", freq="3D")
348+
pidx = period_range(start="2014-01-02", end="2014-01-15", freq="3D")
384349
expected = PeriodIndex(
385350
["2014-01-02", "2014-01-05", "2014-01-08", "2014-01-11", "2014-01-14"],
386351
freq="3D",
387352
)
388353
tm.assert_index_equal(pidx, expected)
389354

390-
with tm.assert_produces_warning(warning):
391-
pidx = func(end="2014-01-01 17:00", freq="4H", periods=3)
355+
pidx = period_range(end="2014-01-01 17:00", freq="4H", periods=3)
392356
expected = PeriodIndex(
393357
["2014-01-01 09:00", "2014-01-01 13:00", "2014-01-01 17:00"], freq="4H"
394358
)
@@ -425,18 +389,6 @@ def test_constructor_freq_combined(self):
425389
expected = PeriodIndex(["2016-01-01 00:00", "2016-01-02 01:00"], freq="25H")
426390
tm.assert_index_equal(pidx, expected)
427391

428-
def test_constructor_range_based_deprecated(self):
429-
with tm.assert_produces_warning(FutureWarning):
430-
pi = PeriodIndex(freq="A", start="1/1/2001", end="12/1/2009")
431-
assert len(pi) == 9
432-
433-
def test_constructor_range_based_deprecated_different_freq(self):
434-
with tm.assert_produces_warning(FutureWarning) as m:
435-
PeriodIndex(start="2000", periods=2)
436-
437-
(warning,) = m
438-
assert 'freq="A-DEC"' in str(warning.message)
439-
440392
def test_constructor(self):
441393
pi = period_range(freq="A", start="1/1/2001", end="12/1/2009")
442394
assert len(pi) == 9
@@ -507,21 +459,6 @@ def test_constructor(self):
507459
with pytest.raises(IncompatibleFrequency, match=msg):
508460
PeriodIndex(vals)
509461

510-
def test_constructor_error(self):
511-
start = Period("02-Apr-2005", "B")
512-
end_intv = Period("2006-12-31", ("w", 1))
513-
514-
msg = "start and end must have same freq"
515-
with pytest.raises(ValueError, match=msg):
516-
PeriodIndex(start=start, end=end_intv)
517-
518-
msg = (
519-
"Of the three parameters: start, end, and periods, "
520-
"exactly two must be specified"
521-
)
522-
with pytest.raises(ValueError, match=msg):
523-
PeriodIndex(start=start)
524-
525462
@pytest.mark.parametrize(
526463
"freq", ["M", "Q", "A", "D", "B", "T", "S", "L", "U", "N", "H"]
527464
)

pandas/tests/indexes/period/test_period.py

-5
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,10 @@ def test_pindex_qaccess(self):
529529
assert s["05Q4"] == s[2]
530530

531531
def test_pindex_multiples(self):
532-
with tm.assert_produces_warning(FutureWarning):
533-
pi = PeriodIndex(start="1/1/11", end="12/31/11", freq="2M")
534532
expected = PeriodIndex(
535533
["2011-01", "2011-03", "2011-05", "2011-07", "2011-09", "2011-11"],
536534
freq="2M",
537535
)
538-
tm.assert_index_equal(pi, expected)
539-
assert pi.freq == offsets.MonthEnd(2)
540-
assert pi.freqstr == "2M"
541536

542537
pi = period_range(start="1/1/11", end="12/31/11", freq="2M")
543538
tm.assert_index_equal(pi, expected)

pandas/tests/indexes/timedeltas/test_construction.py

-14
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010

1111

1212
class TestTimedeltaIndex:
13-
def test_verify_integrity_deprecated(self):
14-
# GH#23919
15-
with tm.assert_produces_warning(FutureWarning):
16-
TimedeltaIndex(["1 Day"], verify_integrity=False)
17-
18-
def test_range_kwargs_deprecated(self):
19-
# GH#23919
20-
with tm.assert_produces_warning(FutureWarning):
21-
TimedeltaIndex(start="1 Day", end="3 Days", freq="D")
22-
2313
def test_int64_nocopy(self):
2414
# GH#23539 check that a copy isn't made when we pass int64 data
2515
# and copy=False
@@ -166,10 +156,6 @@ def test_constructor_coverage(self):
166156
with pytest.raises(TypeError, match=msg):
167157
timedelta_range(start="1 days", periods="foo", freq="D")
168158

169-
with pytest.raises(ValueError):
170-
with tm.assert_produces_warning(FutureWarning):
171-
TimedeltaIndex(start="1 days", end="10 days")
172-
173159
with pytest.raises(TypeError):
174160
TimedeltaIndex("1 days")
175161

0 commit comments

Comments
 (0)