Skip to content

DOC: update the Period.dayofyear docstring #20277

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

Merged
merged 2 commits into from
Mar 13, 2018

Conversation

techytushar
Copy link
Contributor

@techytushar techytushar commented Mar 11, 2018

Signed-off-by: Tushar Mittal [email protected]

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
##################### Docstring (pandas.Period.dayofyear)  #####################
################################################################################

Return the day of the year.

This attribute returns the day of the year on which the particular
date occurs. The return value ranges between 1 to 365 for regular
years and 1 to 366 for leap years.

Returns
-------
int
    The day of year.

See Also
--------
Period.dayofweek : Return the day of week.
Period.daysinmonth : Return the days in that month.
PeriodIndex.dayofyear : Return the day of year of all indexes. 

Examples
--------
>>> period = pd.Period("2015-10-23", freq='H')
>>> period.dayofyear
296
>>> period = pd.Period("2012-12-31", freq='D')
>>> period.dayofyear
366
>>> period = pd.Period("2013-01-01", freq='D')
>>> period.dayofyear
1

################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.Period.dayofyear" correct. :)

If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.

@techytushar
Copy link
Contributor Author

@jreback please review 🙂

Returns
-------
int
The day of year.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be indented 4 space.

--------
Period.dayofweek : Return the day of week.
Period.daysinmonth : Return the days in that month.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add PeriodIndex.dayofyear

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean 'weekofyear' ? (dayofyear is the current docstring)

@@ -1255,6 +1255,33 @@ cdef class _Period(object):

@property
def dayofyear(self):
"""
Return the day of the year.
Copy link
Contributor

Choose a reason for hiding this comment

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

Periods represent time spans so it's good to note that this is the start of the period. So maybe

Return the day of the year the of the Period's start.

That's a bit wordy though. Feel free to reword if you have a better phrasing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, but I didn't understand the meaning of the sentence Return the day of the year the of the Period's start., specifically of the period's start

Copy link
Contributor

@TomAugspurger TomAugspurger Mar 12, 2018

Choose a reason for hiding this comment

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

Period is a span, so saying "Day of the year" is a bit ambiguous. Is it the start, end, somewhere in between?

If you have a period like `Period('2017-01-01', freq='A')

In [2]: pd.Period('2017-01-01', freq='A')
Out[2]: Period('2017', 'A-DEC')

In [3]: pd.Period('2017-01-01', freq='A').day
Out[3]: 31

I was apparently wrong about it always being the start. I guess it's related to freq

Copy link
Member

Choose a reason for hiding this comment

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

This comment will be relevant to many of the Period attributes like day, dayofyear, .. (also the ones I already merged ..).
So it would be good to be consistent in it.

The annual frequency is by default a "year-end" frequency, so it's indeed freq related.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, I don't follow... Can you show two cases creating a period starting on the same day but with different frequencies, and how this affect .day, .dayofweek, .dayofyear, etc.?

Copy link
Member

Choose a reason for hiding this comment

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

@dukebody small example:

In [30]: p1 = pd.Period('2017-01-01', freq='D')

In [31]: p2 = pd.Period('2017-01-01', freq='M')

In [32]: p1
Out[32]: Period('2017-01-01', 'D')

In [33]: p2
Out[33]: Period('2017-01', 'M')

In [34]: p1.start_time
Out[34]: Timestamp('2017-01-01 00:00:00')

In [35]: p2.start_time
Out[35]: Timestamp('2017-01-01 00:00:00')

In [36]: p1.dayofyear
Out[36]: 1

In [37]: p2.dayofyear
Out[37]: 31

I am not really familiar with this frequency business, but you have certain frequences which are "anchored" at the beginning of the period, and others at the end of the period. But I don't directly see a way how to inspect this.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's quite confusing. Should we open a ticket to make .dayofyear etc. always refer to the start time of the period? Not to the "anchored" time. Otherwise these functions are very unpredictable IMO and therefore don't add a lot of value.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I am writing one currently ;)
I suppose those attributes will mainly be useful for frequencies <= 1D

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm OK with merging this PR without referring to the start or end date of the period, and then work on code to make this predictable and change all docstrings to refer to the period start date.

@techytushar
Copy link
Contributor Author

made the required changes, please review @jorisvandenbossche 🙂

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Apart from the discussion about start/end in the summary line, looks good to me!

@jorisvandenbossche jorisvandenbossche modified the milestones: 1.0, 0.23.0 Mar 13, 2018
@jorisvandenbossche
Copy link
Member

Apart from the discussion about start/end in the summary line

Let's merge this, and will open a new issue to further discuss the confusion around start/end of the period. We can later fix the wording of the summary line.

@jorisvandenbossche jorisvandenbossche merged commit ed77b5b into pandas-dev:master Mar 13, 2018
@jorisvandenbossche
Copy link
Member

@techytushar Thanks a lot!

@jorisvandenbossche
Copy link
Member

I opened an issue here: #20324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants