Skip to content

Commit e644d8c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into disown-tz-only-rebased
Conflicts: 1. Preserved the new inheritance structure 2. Used the delegate_names from master (may be redundant?) Changes: 1. Replaced _eadata with _data in delegate, to avoid infinite recursion
2 parents 7a5fd94 + ab55d05 commit e644d8c

30 files changed

+1915
-1688
lines changed

.travis.yml

-16
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ matrix:
3636
env:
3737
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="not slow and not network"
3838

39-
- dist: trusty
40-
env:
41-
- JOB="2.7, locale, slow, old NumPy" ENV_FILE="ci/deps/travis-27-locale.yaml" LOCALE_OVERRIDE="zh_CN.UTF-8" PATTERN="slow"
42-
addons:
43-
apt:
44-
packages:
45-
- language-pack-zh-hans
46-
4739
- dist: trusty
4840
env:
4941
- JOB="2.7" ENV_FILE="ci/deps/travis-27.yaml" PATTERN="not slow"
@@ -60,14 +52,6 @@ matrix:
6052
env:
6153
- JOB="3.6, coverage" ENV_FILE="ci/deps/travis-36.yaml" PATTERN="not slow and not network" PANDAS_TESTING_MODE="deprecate" COVERAGE=true
6254

63-
- dist: trusty
64-
env:
65-
- JOB="3.7, NumPy dev" ENV_FILE="ci/deps/travis-37-numpydev.yaml" PATTERN="not slow and not network" TEST_ARGS="-W error" PANDAS_TESTING_MODE="deprecate"
66-
addons:
67-
apt:
68-
packages:
69-
- xsel
70-
7155
# In allow_failures
7256
- dist: trusty
7357
env:

asv_bench/benchmarks/period.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pandas import (DataFrame, Series, Period, PeriodIndex, date_range,
2-
period_range)
1+
from pandas import (
2+
DataFrame, Period, PeriodIndex, Series, date_range, period_range)
33

44

55
class PeriodProperties(object):
@@ -94,7 +94,7 @@ def time_value_counts(self, typ):
9494
class Indexing(object):
9595

9696
def setup(self):
97-
self.index = PeriodIndex(start='1985', periods=1000, freq='D')
97+
self.index = period_range(start='1985', periods=1000, freq='D')
9898
self.series = Series(range(1000), index=self.index)
9999
self.period = self.index[500]
100100

ci/azure/posix.yml

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,36 @@ jobs:
2020
CONDA_PY: "27"
2121
PATTERN: "not slow and not network"
2222

23-
py37_locale:
24-
ENV_FILE: ci/deps/azure-37-locale.yaml
25-
CONDA_PY: "37"
26-
PATTERN: "not slow and not network"
23+
py27_locale_slow_old_np:
24+
ENV_FILE: ci/deps/azure-27-locale.yaml
25+
CONDA_PY: "27"
26+
PATTERN: "slow"
2727
LOCALE_OVERRIDE: "zh_CN.UTF-8"
28+
EXTRA_APT: "language-pack-zh-hans"
2829

2930
py36_locale_slow:
3031
ENV_FILE: ci/deps/azure-36-locale_slow.yaml
3132
CONDA_PY: "36"
3233
PATTERN: "not slow and not network"
3334
LOCALE_OVERRIDE: "it_IT.UTF-8"
3435

36+
py37_locale:
37+
ENV_FILE: ci/deps/azure-37-locale.yaml
38+
CONDA_PY: "37"
39+
PATTERN: "not slow and not network"
40+
LOCALE_OVERRIDE: "zh_CN.UTF-8"
41+
42+
py37_np_dev:
43+
ENV_FILE: ci/deps/azure-37-numpydev.yaml
44+
CONDA_PY: "37"
45+
PATTERN: "not slow and not network"
46+
TEST_ARGS: "-W error"
47+
PANDAS_TESTING_MODE: "deprecate"
48+
EXTRA_APT: "xsel"
49+
3550
steps:
3651
- script: |
37-
if [ "$(uname)" == "Linux" ]; then sudo apt-get install -y libc6-dev-i386; fi
52+
if [ "$(uname)" == "Linux" ]; then sudo apt-get install -y libc6-dev-i386 $EXTRA_APT; fi
3853
echo "Installing Miniconda"
3954
ci/incremental/install_miniconda.sh
4055
export PATH=$HOME/miniconda3/bin:$PATH
File renamed without changes.
File renamed without changes.

doc/source/whatsnew/v0.21.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Previous Behavior:
654654

655655
.. code-block:: ipython
656656
657-
In [1]: pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
657+
In [1]: pi = pd.period_range(start='2000-01-01', freq='D', periods=10)
658658
659659
In [2]: s = pd.Series(np.arange(10), index=pi)
660660
@@ -674,7 +674,7 @@ New Behavior:
674674

675675
.. ipython:: python
676676
677-
pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
677+
pi = pd.period_range(start='2000-01-01', freq='D', periods=10)
678678
679679
s = pd.Series(np.arange(10), index=pi)
680680

doc/source/whatsnew/v0.24.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ Deprecations
11741174
- Timezone converting a tz-aware ``datetime.datetime`` or :class:`Timestamp` with :class:`Timestamp` and the ``tz`` argument is now deprecated. Instead, use :meth:`Timestamp.tz_convert` (:issue:`23579`)
11751175
- :func:`pandas.api.types.is_period` is deprecated in favor of `pandas.api.types.is_period_dtype` (:issue:`23917`)
11761176
- :func:`pandas.api.types.is_datetimetz` is deprecated in favor of `pandas.api.types.is_datetime64tz` (:issue:`23917`)
1177-
- Creating a :class:`TimedeltaIndex` or :class:`DatetimeIndex` by passing range arguments `start`, `end`, and `periods` is deprecated in favor of :func:`timedelta_range` and :func:`date_range` (:issue:`23919`)
1177+
- Creating a :class:`TimedeltaIndex`, :class:`DatetimeIndex`, or :class:`PeriodIndex` by passing range arguments `start`, `end`, and `periods` is deprecated in favor of :func:`timedelta_range`, :func:`date_range`, or :func:`period_range` (:issue:`23919`)
11781178
- Passing a string alias like ``'datetime64[ns, UTC]'`` as the ``unit`` parameter to :class:`DatetimeTZDtype` is deprecated. Use :class:`DatetimeTZDtype.construct_from_string` instead (:issue:`23990`).
11791179
- In :meth:`Series.where` with Categorical data, providing an ``other`` that is not present in the categories is deprecated. Convert the categorical to a different dtype or add the ``other`` to the categories first (:issue:`24077`).
11801180
- :meth:`Series.clip_lower`, :meth:`Series.clip_upper`, :meth:`DataFrame.clip_lower` and :meth:`DataFrame.clip_upper` are deprecated and will be removed in a future version. Use ``Series.clip(lower=threshold)``, ``Series.clip(upper=threshold)`` and the equivalent ``DataFrame`` methods (:issue:`24203`)
@@ -1337,6 +1337,7 @@ Datetimelike
13371337
- Bug in :meth:`Series.combine_first` not properly aligning categoricals, so that missing values in ``self`` where not filled by valid values from ``other`` (:issue:`24147`)
13381338
- Bug in :func:`DataFrame.combine` with datetimelike values raising a TypeError (:issue:`23079`)
13391339
- Bug in :func:`date_range` with frequency of ``Day`` or higher where dates sufficiently far in the future could wrap around to the past instead of raising ``OutOfBoundsDatetime`` (:issue:`14187`)
1340+
- Bug in :func:`period_range` ignoring the frequency of ``start`` and ``end`` when those are provided as :class:`Period` objects (:issue:`20535`).
13401341
- Bug in :class:`PeriodIndex` with attribute ``freq.n`` greater than 1 where adding a :class:`DateOffset` object would return incorrect results (:issue:`23215`)
13411342
- Bug in :class:`Series` that interpreted string indices as lists of characters when setting datetimelike values (:issue:`23451`)
13421343
- Bug in :class:`DataFrame` when creating a new column from an ndarray of :class:`Timestamp` objects with timezones creating an object-dtype column, rather than datetime with timezone (:issue:`23932`)

pandas/core/indexes/datetimes.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DatetimeDelegateMixin(DatetimelikeDelegateMixin):
6262
# We also have a few "extra" attrs, which may or may not be raw,
6363
# which we we dont' want to expose in the .dt accessor.
6464
_extra_methods = [
65+
'to_period',
6566
'to_perioddelta',
6667
'to_julian_date',
6768
]
@@ -90,6 +91,11 @@ class DatetimeDelegateMixin(DatetimelikeDelegateMixin):
9091
_delegate_class = DatetimeArray
9192

9293

94+
@delegate_names(DatetimeArray, ["to_period", "tz_localize", "tz_convert",
95+
"day_name", "month_name"],
96+
typ="method", overwrite=True)
97+
@delegate_names(DatetimeArray,
98+
DatetimeArray._field_ops, typ="property", overwrite=True)
9399
@delegate_names(DatetimeArray,
94100
DatetimeDelegateMixin._delegated_properties,
95101
typ="property")
@@ -119,15 +125,27 @@ class DatetimeIndex(DatelikeIndexMixin,
119125
start : starting value, datetime-like, optional
120126
If data is None, start is used as the start point in generating regular
121127
timestamp data.
128+
129+
.. deprecated:: 0.24.0
130+
122131
periods : int, optional, > 0
123132
Number of periods to generate, if generating index. Takes precedence
124133
over end argument
125-
end : end time, datetime-like, optional
134+
135+
.. deprecated:: 0.24.0
136+
137+
end : end time, datetime-like, optional
126138
If periods is none, generated index will extend to first conforming
127139
time on or just past end argument
140+
141+
.. deprecated:: 0.24.0
142+
128143
closed : string or None, default None
129144
Make the interval closed with respect to the given frequency to
130145
the 'left', 'right', or both sides (None)
146+
147+
.. deprecated:: 0.24. 0
148+
131149
tz : pytz.timezone or dateutil.tz.tzfile
132150
ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
133151
When clocks moved backward due to DST, ambiguous times may arise.
@@ -204,12 +222,16 @@ class DatetimeIndex(DatelikeIndexMixin,
204222
To learn more about the frequency strings, please see `this link
205223
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
206224
225+
Creating a DatetimeIndex based on `start`, `periods`, and `end` has
226+
been deprecated in favor of :func:`date_range`.
227+
207228
See Also
208229
---------
209230
Index : The base pandas Index type.
210231
TimedeltaIndex : Index of timedelta64 data.
211232
PeriodIndex : Index of Period data.
212-
pandas.to_datetime : Convert argument to datetime.
233+
to_datetime : Convert argument to datetime.
234+
date_range : Create a fixed-frequency DatetimeIndex.
213235
"""
214236
_typ = 'datetimeindex'
215237
_join_precedence = 10
@@ -261,16 +283,16 @@ def __new__(cls, data=None,
261283
verify_integrity = True
262284

263285
if data is None:
286+
result = DatetimeArray._generate_range(
287+
start, end, periods,
288+
freq=freq, tz=tz, normalize=normalize,
289+
closed=closed, ambiguous=ambiguous)
264290
warnings.warn("Creating a DatetimeIndex by passing range "
265291
"endpoints is deprecated. Use "
266292
"`pandas.date_range` instead.",
267293
FutureWarning, stacklevel=2)
268-
result = DatetimeArray._generate_range(start, end, periods,
269-
freq=freq, tz=tz,
270-
normalize=normalize,
271-
closed=closed,
272-
ambiguous=ambiguous)
273-
return cls._simple_new(result, name=name)
294+
295+
return cls(result, name=name)
274296

275297
if is_scalar(data):
276298
raise TypeError("{cls}() must be called with a "

pandas/core/indexes/period.py

+55-10
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,21 @@ class PeriodIndex(DatetimeIndexOpsMixin,
9292
start : starting value, period-like, optional
9393
If data is None, used as the start point in generating regular
9494
period data.
95+
96+
.. deprecated:: 0.24.0
97+
9598
periods : int, optional, > 0
9699
Number of periods to generate, if generating index. Takes precedence
97100
over end argument
101+
102+
.. deprecated:: 0.24.0
103+
98104
end : end value, period-like, optional
99105
If periods is none, generated index will extend to first conforming
100106
period on or just past end argument
107+
108+
.. deprecated:: 0.24.0
109+
101110
year : int, array, or Series, default None
102111
month : int, array, or Series, default None
103112
quarter : int, array, or Series, default None
@@ -138,18 +147,22 @@ class PeriodIndex(DatetimeIndexOpsMixin,
138147
strftime
139148
to_timestamp
140149
150+
Notes
151+
-----
152+
Creating a PeriodIndex based on `start`, `periods`, and `end` has
153+
been deprecated in favor of :func:`period_range`.
154+
141155
Examples
142156
--------
143157
>>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr)
144158
145-
>>> idx2 = pd.PeriodIndex(start='2000', end='2010', freq='A')
146-
147159
See Also
148160
---------
149161
Index : The base pandas Index type.
150162
Period : Represents a period of time.
151163
DatetimeIndex : Index with datetime64 data.
152164
TimedeltaIndex : Index of timedelta64 data.
165+
period_range : Create a fixed-frequency PeriodIndex.
153166
"""
154167
_typ = 'periodindex'
155168
_attributes = ['name', 'freq']
@@ -181,8 +194,32 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None,
181194

182195
if data is None and ordinal is None:
183196
# range-based.
184-
data, freq = PeriodArray._generate_range(start, end, periods,
185-
freq, fields)
197+
data, freq2 = PeriodArray._generate_range(start, end, periods,
198+
freq, fields)
199+
# PeriodArray._generate range does validate that fields is
200+
# empty when really using the range-based constructor.
201+
if not fields:
202+
msg = ("Creating a PeriodIndex by passing range "
203+
"endpoints is deprecated. Use "
204+
"`pandas.period_range` instead.")
205+
# period_range differs from PeriodIndex for cases like
206+
# start="2000", periods=4
207+
# PeriodIndex interprets that as A-DEC freq.
208+
# period_range interprets it as 'D' freq.
209+
cond = (
210+
freq is None and (
211+
(start and not isinstance(start, Period)) or
212+
(end and not isinstance(end, Period))
213+
)
214+
)
215+
if cond:
216+
msg += (
217+
" Note that the default `freq` may differ. Pass "
218+
"'freq=\"{}\"' to ensure the same output."
219+
).format(freq2.freqstr)
220+
warnings.warn(msg, FutureWarning, stacklevel=2)
221+
freq = freq2
222+
186223
data = PeriodArray(data, freq=freq)
187224
else:
188225
freq = validate_dtype_freq(dtype, freq)
@@ -893,7 +930,7 @@ def base(self):
893930
PeriodIndex._add_datetimelike_methods()
894931

895932

896-
def period_range(start=None, end=None, periods=None, freq='D', name=None):
933+
def period_range(start=None, end=None, periods=None, freq=None, name=None):
897934
"""
898935
Return a fixed frequency PeriodIndex, with day (calendar) as the default
899936
frequency
@@ -906,8 +943,11 @@ def period_range(start=None, end=None, periods=None, freq='D', name=None):
906943
Right bound for generating periods
907944
periods : integer, default None
908945
Number of periods to generate
909-
freq : string or DateOffset, default 'D'
910-
Frequency alias
946+
freq : string or DateOffset, optional
947+
Frequency alias. By default the freq is taken from `start` or `end`
948+
if those are Period objects. Otherwise, the default is ``"D"`` for
949+
daily frequency.
950+
911951
name : string, default None
912952
Name of the resulting PeriodIndex
913953
@@ -944,6 +984,11 @@ def period_range(start=None, end=None, periods=None, freq='D', name=None):
944984
if com.count_not_none(start, end, periods) != 2:
945985
raise ValueError('Of the three parameters: start, end, and periods, '
946986
'exactly two must be specified')
947-
948-
return PeriodIndex(start=start, end=end, periods=periods,
949-
freq=freq, name=name)
987+
if freq is None and (not isinstance(start, Period)
988+
and not isinstance(end, Period)):
989+
freq = 'D'
990+
991+
data, freq = PeriodArray._generate_range(start, end, periods, freq,
992+
fields={})
993+
data = PeriodArray(data, freq=freq)
994+
return PeriodIndex(data, name=name)

pandas/core/indexes/timedeltas.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class TimedeltaDelegateMixin(DatetimelikeDelegateMixin):
6464
}
6565

6666

67+
@delegate_names(TimedeltaArray,
68+
["to_pytimedelta", "total_seconds"],
69+
typ="method", overwrite=True)
70+
@delegate_names(TimedeltaArray,
71+
["days", "seconds", "microseconds", "nanoseconds"],
72+
typ="property", overwrite=True)
6773
@delegate_names(TimedeltaArray,
6874
TimedeltaDelegateMixin._delegated_properties,
6975
typ="property")
@@ -94,15 +100,27 @@ class TimedeltaIndex(DatetimeIndexOpsMixin,
94100
start : starting value, timedelta-like, optional
95101
If data is None, start is used as the start point in generating regular
96102
timedelta data.
103+
104+
.. deprecated:: 0.24.0
105+
97106
periods : int, optional, > 0
98107
Number of periods to generate, if generating index. Takes precedence
99108
over end argument
100-
end : end time, timedelta-like, optional
109+
110+
.. deprecated:: 0.24.0
111+
112+
end : end time, timedelta-like, optional
101113
If periods is none, generated index will extend to first conforming
102114
time on or just past end argument
115+
116+
.. deprecated:: 0.24. 0
117+
103118
closed : string or None, default None
104119
Make the interval closed with respect to the given frequency to
105120
the 'left', 'right', or both sides (None)
121+
122+
.. deprecated:: 0.24. 0
123+
106124
name : object
107125
Name to be stored in the index
108126
@@ -130,12 +148,15 @@ class TimedeltaIndex(DatetimeIndexOpsMixin,
130148
Timedelta : Represents a duration between two dates or times.
131149
DatetimeIndex : Index of datetime64 data.
132150
PeriodIndex : Index of Period data.
151+
timedelta_range : Create a fixed-frequency TimedeltaIndex.
133152
134153
Notes
135154
-----
136-
137155
To learn more about the frequency strings, please see `this link
138156
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
157+
158+
Creating a TimedeltaIndex based on `start`, `periods`, and `end` has
159+
been deprecated in favor of :func:`timedelta_range`.
139160
"""
140161

141162
_typ = 'timedeltaindex'

0 commit comments

Comments
 (0)