Skip to content

DOC: Fixed examples in pandas/core/indexes/ #33208

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

Conversation

ShaharNaveh
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm

@WillAyd WillAyd added this to the 1.1 milestone Apr 1, 2020
@@ -200,13 +232,24 @@ class TimedeltaProperties(Properties):
"""
Accessor object for datetimelike properties of the Series values.

Examples
--------
>>> s.dt.hours
Copy link
Member Author

Choose a reason for hiding this comment

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

Forgot to mention, I could not manage to give an example for s.dt.hours,

I tried to have:

import pandas as pd
hours_series = pd.Series(pd.timedelta_range(start="1 day", periods=3, freq="H"))

And then:

hours_series.dt.hours

and

 hours_series.dt.hour

but both gives:

AttributeError: 'TimedeltaProperties' object has no attribute 'hour'
AttributeError: 'TimedeltaProperties' object has no attribute 'hours'

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 see if there is an issue for this.

>>> s = pd.Series(pd.timedelta_range(start="1 day", periods=3, freq="H"))
>>> s
0   1 days 00:00:00
1   1 days 01:00:00
2   1 days 02:00:00
dtype: timedelta64[ns]
>>>
>>> s.dt.components
   days  hours  minutes  seconds  milliseconds  microseconds  nanoseconds
0     1      0        0        0             0             0            0
1     1      1        0        0             0             0            0
2     1      2        0        0             0             0            0

Copy link
Member Author

Choose a reason for hiding this comment

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

I could not find an issue for this, so I opened one here:

xref #33255

0 1
1 2
2 3
dtype: int64
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether needs to be in the class description.

with help(pd.core.indexes.accessors.DatetimeProperties)

under Data descriptors defined here:

we have

| dayofweek
| The day of the week with Monday=0, Sunday=6.
|
| Return the day of the week. It is assumed the week starts on
| Monday, which is denoted by 0 and ends on Sunday which is denoted
| by 6. This method is available on both Series with datetime
| values (using the dt accessor) or DatetimeIndex.
|

Returns
Series or Index
Containing integers indicating the day number.

|

See Also
Series.dt.dayofweek : Alias.
Series.dt.weekday : Alias.
Series.dt.day_name : Returns the name of the day of the week.

|

Examples
>>> s = pd.date_range('2016-12-31', '2017-01-08', freq='D').to_series()
>>> s.dt.dayofweek
2016-12-31 5
2017-01-01 6
2017-01-02 0
2017-01-03 1
2017-01-04 2
2017-01-05 3
2017-01-06 4
2017-01-07 5
2017-01-08 6
Freq: D, dtype: int64

and for hour, second and quarter we just have

| hour
| The hours of the datetime.

second
| The seconds of the datetime.

| quarter
| The quarter of the date.

maybe these examples should be in the descriptor docstrings instead. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe that we should have them for both, because the class's docstring is telling the user/developer that this class is responsible for accessing the fields, and some examples on.

And on top of that we should also supply specific examples for each field accessor, would love to do so in a follow up.

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@MomIsBestFriend lgtm. ping on green

@ShaharNaveh
Copy link
Member Author

ping @simonjayhawkins

@simonjayhawkins simonjayhawkins merged commit 513d3e2 into pandas-dev:master Apr 3, 2020
@simonjayhawkins
Copy link
Member

Thanks @MomIsBestFriend

@ShaharNaveh ShaharNaveh deleted the DOC-DocTests-core-indexes branch April 3, 2020 10:57
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.

3 participants