Skip to content

day_of_year #25924

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6794685
day_of_year
oleksii-polovyi Mar 29, 2019
f990e59
Update indexing.rst
oleksii-polovyi Mar 29, 2019
2a372a9
bug fix
oleksii-polovyi Mar 29, 2019
39f4afc
dayofyear
oleksii-polovyi Mar 29, 2019
e89e36d
Update indexing.rst
oleksii-polovyi Mar 29, 2019
0b92861
fix indent
oleksii-polovyi Mar 29, 2019
3372278
indent fix
oleksii-polovyi Mar 29, 2019
37562c0
Merge branch 'master' into issue-9606
Jun 2, 2019
f5038d0
keep dayofyear for deprecation
oleksii-polovyi Jun 2, 2019
f548d01
add day_of_week to params
oleksii-polovyi Jun 2, 2019
adea39b
add days_in_month to params
oleksii-polovyi Jun 2, 2019
5ab6273
fix pep8 issue
oleksii-polovyi Jun 2, 2019
d13907e
fix jreback's suggestion
oleksii-polovyi Jun 2, 2019
8915335
add deprecation warnings
oleksii-polovyi Jun 2, 2019
558f804
fix version in deprecate(...)
oleksii-polovyi Jun 2, 2019
4035c73
fix redirects.csv
oleksii-polovyi Jun 2, 2019
f129f12
fix redirects.csv
oleksii-polovyi Jun 2, 2019
192cfcb
update dayofyear and dayofweek
oleksii-polovyi Jun 2, 2019
cc48825
fix dayofweek and dayofyear
oleksii-polovyi Jun 2, 2019
30a4d91
update dayofyear and dayofweek
oleksii-polovyi Jun 2, 2019
8eed38c
update dayofyear and dayofweek
oleksii-polovyi Jun 2, 2019
da53b42
update timeseries.rst
oleksii-polovyi Jun 2, 2019
6428c34
update nattype.pyx
oleksii-polovyi Jun 2, 2019
aa03180
day_of_week and day_of_year
oleksii-polovyi Jun 2, 2019
e3d3e5c
update test_timestamp.py
oleksii-polovyi Jun 2, 2019
67eec73
update test_period.py
oleksii-polovyi Jun 2, 2019
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
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PeriodProperties(object):
params = (['M', 'min'],
['year', 'month', 'day', 'hour', 'minute', 'second',
'is_leap_year', 'quarter', 'qyear', 'week', 'daysinmonth',
'dayofweek', 'dayofyear', 'start_time', 'end_time'])
'dayofweek', 'day_of_year', 'start_time', 'end_time'])
param_names = ['freq', 'attr']

def setup(self, freq, attr):
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def time_weekday_name(self, tz, freq):
self.ts.day_name

def time_dayofyear(self, tz, freq):
self.ts.dayofyear
self.ts.day_of_year

def time_week(self, tz, freq):
self.ts.week
Expand Down
10 changes: 5 additions & 5 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ generated/pandas.DatetimeIndex.date,../reference/api/pandas.DatetimeIndex.date
generated/pandas.DatetimeIndex.day,../reference/api/pandas.DatetimeIndex.day
generated/pandas.DatetimeIndex.day_name,../reference/api/pandas.DatetimeIndex.day_name
generated/pandas.DatetimeIndex.dayofweek,../reference/api/pandas.DatetimeIndex.dayofweek
generated/pandas.DatetimeIndex.dayofyear,../reference/api/pandas.DatetimeIndex.dayofyear
generated/pandas.DatetimeIndex.day_of_year,../reference/api/pandas.DatetimeIndex.day_of_year
generated/pandas.DatetimeIndex.floor,../reference/api/pandas.DatetimeIndex.floor
generated/pandas.DatetimeIndex.freq,../reference/api/pandas.DatetimeIndex.freq
generated/pandas.DatetimeIndex.freqstr,../reference/api/pandas.DatetimeIndex.freqstr
Expand Down Expand Up @@ -1005,7 +1005,7 @@ generated/pandas.Panel.xs,../reference/api/pandas.Panel.xs
generated/pandas.Period.asfreq,../reference/api/pandas.Period.asfreq
generated/pandas.Period.day,../reference/api/pandas.Period.day
generated/pandas.Period.dayofweek,../reference/api/pandas.Period.dayofweek
generated/pandas.Period.dayofyear,../reference/api/pandas.Period.dayofyear
generated/pandas.Period.day_of_year,../reference/api/pandas.Period.day_of_year
generated/pandas.Period.days_in_month,../reference/api/pandas.Period.days_in_month
generated/pandas.Period.daysinmonth,../reference/api/pandas.Period.daysinmonth
generated/pandas.Period.end_time,../reference/api/pandas.Period.end_time
Expand All @@ -1016,7 +1016,7 @@ generated/pandas.Period,../reference/api/pandas.Period
generated/pandas.PeriodIndex.asfreq,../reference/api/pandas.PeriodIndex.asfreq
generated/pandas.PeriodIndex.day,../reference/api/pandas.PeriodIndex.day
generated/pandas.PeriodIndex.dayofweek,../reference/api/pandas.PeriodIndex.dayofweek
generated/pandas.PeriodIndex.dayofyear,../reference/api/pandas.PeriodIndex.dayofyear
generated/pandas.PeriodIndex.day_of_year,../reference/api/pandas.PeriodIndex.day_of_year
generated/pandas.PeriodIndex.days_in_month,../reference/api/pandas.PeriodIndex.days_in_month
generated/pandas.PeriodIndex.daysinmonth,../reference/api/pandas.PeriodIndex.daysinmonth
generated/pandas.PeriodIndex.end_time,../reference/api/pandas.PeriodIndex.end_time
Expand Down Expand Up @@ -1162,7 +1162,7 @@ generated/pandas.Series.dt.date,../reference/api/pandas.Series.dt.date
generated/pandas.Series.dt.day,../reference/api/pandas.Series.dt.day
generated/pandas.Series.dt.day_name,../reference/api/pandas.Series.dt.day_name
generated/pandas.Series.dt.dayofweek,../reference/api/pandas.Series.dt.dayofweek
generated/pandas.Series.dt.dayofyear,../reference/api/pandas.Series.dt.dayofyear
generated/pandas.Series.dt.day_of_year,../reference/api/pandas.Series.dt.day_of_year
generated/pandas.Series.dt.days,../reference/api/pandas.Series.dt.days
generated/pandas.Series.dt.days_in_month,../reference/api/pandas.Series.dt.days_in_month
generated/pandas.Series.dt.daysinmonth,../reference/api/pandas.Series.dt.daysinmonth
Expand Down Expand Up @@ -1507,7 +1507,7 @@ generated/pandas.Timestamp.date,../reference/api/pandas.Timestamp.date
generated/pandas.Timestamp.day,../reference/api/pandas.Timestamp.day
generated/pandas.Timestamp.day_name,../reference/api/pandas.Timestamp.day_name
generated/pandas.Timestamp.dayofweek,../reference/api/pandas.Timestamp.dayofweek
generated/pandas.Timestamp.dayofyear,../reference/api/pandas.Timestamp.dayofyear
generated/pandas.Timestamp.day_of_year,../reference/api/pandas.Timestamp.day_of_year
generated/pandas.Timestamp.days_in_month,../reference/api/pandas.Timestamp.days_in_month
generated/pandas.Timestamp.daysinmonth,../reference/api/pandas.Timestamp.daysinmonth
generated/pandas.Timestamp.dst,../reference/api/pandas.Timestamp.dst
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Properties
Timestamp.asm8
Timestamp.day
Timestamp.dayofweek
Timestamp.dayofyear
Timestamp.day_of_year
Timestamp.days_in_month
Timestamp.daysinmonth
Timestamp.fold
Expand Down Expand Up @@ -223,7 +223,7 @@ Properties

Period.day
Period.dayofweek
Period.dayofyear
Period.day_of_year
Period.days_in_month
Period.daysinmonth
Period.end_time
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Time/Date Components
DatetimeIndex.date
DatetimeIndex.time
DatetimeIndex.timetz
DatetimeIndex.dayofyear
DatetimeIndex.day_of_year
DatetimeIndex.weekofyear
DatetimeIndex.week
DatetimeIndex.dayofweek
Expand Down Expand Up @@ -452,7 +452,7 @@ Properties

PeriodIndex.day
PeriodIndex.dayofweek
PeriodIndex.dayofyear
PeriodIndex.day_of_year
PeriodIndex.days_in_month
PeriodIndex.daysinmonth
PeriodIndex.end_time
Expand Down
2 changes: 1 addition & 1 deletion doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Datetime Properties
Series.dt.weekofyear
Series.dt.dayofweek
Series.dt.weekday
Series.dt.dayofyear
Series.dt.day_of_year
Series.dt.quarter
Series.dt.is_month_start
Series.dt.is_month_end
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ There are several time/date properties that one can access from ``Timestamp`` or
date,"Returns datetime.date (does not contain timezone information)"
time,"Returns datetime.time (does not contain timezone information)"
timetz,"Returns datetime.time as local time with timezone information"
dayofyear,"The ordinal day of year"
day_of_year,"The ordinal day of year"
weekofyear,"The week ordinal of the year"
week,"The week ordinal of the year"
dayofweek,"The number of the day of the week with Monday=0, Sunday=6"
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Bug Fixes
- Bug in ``mean()`` where integer dtypes can overflow (:issue:`10172`)
- Bug where ``Panel.from_dict`` does not set dtype when specified (:issue:`10058`)
- Bug in ``Index.union`` raises ``AttributeError`` when passing array-likes. (:issue:`10149`)
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``day_of_year``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)
- Bug in Index repr when using the ``max_seq_items=None`` setting (:issue:`10182`).
- Bug in getting timezone data with ``dateutil`` on various platforms ( :issue:`9059`, :issue:`8639`, :issue:`9663`, :issue:`10121`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class NaTType(_NaT):
nanosecond = property(fget=lambda self: np.nan)

week = property(fget=lambda self: np.nan)
dayofyear = property(fget=lambda self: np.nan)
day_of_year = property(fget=lambda self: np.nan)
weekofyear = property(fget=lambda self: np.nan)
days_in_month = property(fget=lambda self: np.nan)
daysinmonth = property(fget=lambda self: np.nan)
Expand Down
20 changes: 10 additions & 10 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ cdef class _Period(object):
See Also
--------
Period.end_time : Return the end Timestamp.
Period.dayofyear : Return the day of year.
Period.day_of_year : Return the day of year.
Period.daysinmonth : Return the days in that month.
Period.dayofweek : Return the day of the week.

Expand Down Expand Up @@ -1832,7 +1832,7 @@ cdef class _Period(object):
See Also
--------
Period.dayofweek : Get the day of the week.
Period.dayofyear : Get the day of the year.
Period.day_of_year : Get the day of the year.

Examples
--------
Expand Down Expand Up @@ -1978,7 +1978,7 @@ cdef class _Period(object):
Period.dayofweek : Day of the week the period lies in.
Period.weekday : Alias of Period.dayofweek.
Period.day : Day of the month.
Period.dayofyear : Day of the year.
Period.day_of_year : Day of the year.

Examples
--------
Expand Down Expand Up @@ -2029,7 +2029,7 @@ cdef class _Period(object):
Period.dayofweek : Day of the week the period lies in.
Period.weekday : Alias of Period.dayofweek.
Period.day : Day of the month.
Period.dayofyear : Day of the year.
Period.day_of_year : Day of the year.

Examples
--------
Expand Down Expand Up @@ -2061,7 +2061,7 @@ cdef class _Period(object):
return self.dayofweek

@property
def dayofyear(self):
def day_of_year(self):
"""
Return the day of the year.

Expand All @@ -2078,18 +2078,18 @@ cdef class _Period(object):
--------
Period.day : Return the day of the month.
Period.dayofweek : Return the day of week.
PeriodIndex.dayofyear : Return the day of year of all indexes.
PeriodIndex.day_of_year : Return the day of year of all indexes.

Examples
--------
>>> period = pd.Period("2015-10-23", freq='H')
>>> period.dayofyear
>>> period.day_of_year
296
>>> period = pd.Period("2012-12-31", freq='D')
>>> period.dayofyear
>>> period.day_of_year
366
>>> period = pd.Period("2013-01-01", freq='D')
>>> period.dayofyear
>>> period.day_of_year
1
"""
base, mult = get_freq_code(self.freq)
Expand Down Expand Up @@ -2190,7 +2190,7 @@ cdef class _Period(object):
See Also
--------
Period.days_in_month : Return the days of the month.
Period.dayofyear : Return the day of the year.
Period.day_of_year : Return the day of the year.

Examples
--------
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ class Timestamp(_Timestamp):
return self.day_name()

@property
def dayofyear(self):
def day_of_year(self):
"""
Return the day of the year.
"""
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin,
_object_ops = ['weekday_name', 'freq', 'tz']
_field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
'weekofyear', 'week', 'weekday', 'dayofweek',
'dayofyear', 'quarter', 'days_in_month',
'day_of_year', 'quarter', 'days_in_month',
'daysinmonth', 'microsecond',
'nanosecond']
_other_ops = ['date', 'time', 'timetz']
Expand Down Expand Up @@ -1368,8 +1368,8 @@ def date(self):
'weekday_name',
"The name of day in a week (ex: Friday)\n\n.. deprecated:: 0.23.0")

dayofyear = _field_accessor('dayofyear', 'doy',
"The ordinal day of the year.")
day_of_year = _field_accessor('day_of_year', 'doy',
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to preserve the original with a deprecation warning

Copy link
Author

@oleksii-polovyi oleksii-polovyi Apr 18, 2019

Choose a reason for hiding this comment

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

Thank you for your feedback.

"The ordinal day of the year.")
quarter = _field_accessor('quarter', 'q', "The quarter of the date.")
days_in_month = _field_accessor(
'days_in_month',
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
_object_ops = ['start_time', 'end_time', 'freq']
_field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
'weekofyear', 'weekday', 'week', 'dayofweek',
'dayofyear', 'quarter', 'qyear',
'day_of_year', 'quarter', 'qyear',
'days_in_month', 'daysinmonth']
_datetimelike_ops = _field_ops + _object_ops + _bool_ops
_datetimelike_methods = ['strftime', 'to_timestamp', 'asfreq']
Expand Down Expand Up @@ -296,8 +296,8 @@ def __array__(self, dtype=None):
dayofweek = _field_accessor('dayofweek', 10,
"The day of the week with Monday=0, Sunday=6")
weekday = dayofweek
dayofyear = day_of_year = _field_accessor('dayofyear', 9,
"The ordinal day of the year")
day_of_year = _field_accessor('day_of_year', 9,
"The ordinal day of the year")
quarter = _field_accessor('quarter', 2, "The quarter of the date")
qyear = _field_accessor('qyear', 1)
days_in_month = _field_accessor('days_in_month', 11,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin):
date
time
timetz
dayofyear
day_of_year
weekofyear
week
dayofweek
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
----------
day
dayofweek
dayofyear
day_of_year
days_in_month
daysinmonth
end_time
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/datetimes/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def test_datetimeindex_accessors(self):
assert dti.microsecond[0] == 0
assert dti.dayofweek[0] == 3

assert dti.dayofyear[0] == 1
assert dti.dayofyear[120] == 121
assert dti.day_of_year[0] == 1
assert dti.day_of_year[120] == 121

assert dti.weekofyear[0] == 1
assert dti.weekofyear[120] == 18
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_datetimeindex_accessors(self):
assert len(dti.second) == 365
assert len(dti.microsecond) == 365
assert len(dti.dayofweek) == 365
assert len(dti.dayofyear) == 365
assert len(dti.day_of_year) == 365
assert len(dti.weekofyear) == 365
assert len(dti.quarter) == 365
assert len(dti.is_month_start) == 365
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_scalar_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_dti_date_out_of_range(self, data):
DatetimeIndex(data)

@pytest.mark.parametrize('field', [
'dayofweek', 'dayofyear', 'week', 'weekofyear', 'quarter',
'dayofweek', 'day_of_year', 'week', 'weekofyear', 'quarter',
'days_in_month', 'is_month_start', 'is_month_end',
'is_quarter_start', 'is_quarter_end', 'is_year_start',
'is_year_end', 'weekday_name'])
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_period_index_length(self):

def test_fields(self):
# year, month, day, hour, minute
# second, weekofyear, week, dayofweek, weekday, dayofyear, quarter
# second, weekofyear, week, dayofweek, weekday, day_of_year, quarter
# qyear
pi = period_range(freq='A', start='1/1/2001', end='12/1/2005')
self._check_all_fields(pi)
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_fields(self):

def _check_all_fields(self, periodindex):
fields = ['year', 'month', 'day', 'hour', 'minute', 'second',
'weekofyear', 'week', 'dayofweek', 'dayofyear',
'weekofyear', 'week', 'dayofweek', 'day_of_year',
'quarter', 'qyear', 'days_in_month']

periods = list(periodindex)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,10 @@ def test_daily(self):
ts = Series(np.random.randn(len(rng)), index=rng)

annual = pivot_table(DataFrame(ts), index=ts.index.year,
columns=ts.index.dayofyear)
columns=ts.index.day_of_year)
annual.columns = annual.columns.droplevel(0)

doy = np.asarray(ts.index.dayofyear)
doy = np.asarray(ts.index.day_of_year)

for i in range(1, 367):
subset = ts[doy == i]
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def test_properties_daily(self):
assert b_date.month == 1
assert b_date.day == 1
assert b_date.weekday == 0
assert b_date.dayofyear == 1
assert b_date.day_of_year == 1
assert b_date.days_in_month == 31
assert Period(freq='B', year=2012,
month=2, day=1).days_in_month == 29
Expand All @@ -867,7 +867,7 @@ def test_properties_daily(self):
assert d_date.month == 1
assert d_date.day == 1
assert d_date.weekday == 0
assert d_date.dayofyear == 1
assert d_date.day_of_year == 1
assert d_date.days_in_month == 31
assert Period(freq='D', year=2012, month=2,
day=1).days_in_month == 29
Expand All @@ -883,7 +883,7 @@ def test_properties_hourly(self):
assert h_date.month == 1
assert h_date.day == 1
assert h_date.weekday == 0
assert h_date.dayofyear == 1
assert h_date.day_of_year == 1
assert h_date.hour == 0
assert h_date.days_in_month == 31
assert Period(freq='H', year=2012, month=2, day=1,
Expand All @@ -898,7 +898,7 @@ def test_properties_minutely(self):
assert t_date.month == 1
assert t_date.day == 1
assert t_date.weekday == 0
assert t_date.dayofyear == 1
assert t_date.day_of_year == 1
assert t_date.hour == 0
assert t_date.minute == 0
assert t_date.days_in_month == 31
Expand All @@ -915,7 +915,7 @@ def test_properties_secondly(self):
assert s_date.month == 1
assert s_date.day == 1
assert s_date.weekday == 0
assert s_date.dayofyear == 1
assert s_date.day_of_year == 1
assert s_date.hour == 0
assert s_date.minute == 0
assert s_date.second == 0
Expand Down
Loading