Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: DTI/TDI/PI constructor arguments #29930

Merged
merged 7 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/source/whatsnew/v0.15.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the ":okwarning:" a few lines above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okwarning removed + green

periods=10, tz='US/Eastern')
didx
didx.tz_localize(None)
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
37 changes: 1 addition & 36 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -263,9 +262,6 @@ def __new__(
cls,
data=None,
freq=None,
start=None,
end=None,
periods=None,
tz=None,
normalize=False,
closed=None,
Expand All @@ -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 "
Expand Down
27 changes: 2 additions & 25 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ def __new__(
data=None,
ordinal=None,
freq=None,
start=None,
end=None,
periods=None,
tz=None,
dtype=None,
copy=False,
Expand Down Expand Up @@ -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)
jreback marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Expand Down
28 changes: 0 additions & 28 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
14 changes: 0 additions & 14 deletions pandas/tests/indexes/datetimes/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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")

Expand Down
71 changes: 4 additions & 67 deletions pandas/tests/indexes/period/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions pandas/tests/indexes/timedeltas/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down