Skip to content

DOC: fix timestamp timedelta quotes #25118

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 20 commits into from
Mar 30, 2019

Conversation

dcreekp
Copy link
Contributor

@dcreekp dcreekp commented Feb 3, 2019

@dcreekp
Copy link
Contributor Author

dcreekp commented Feb 3, 2019

The problem is these ones are still left because pandas inherits these docstrings from cpython's datetime library:

$ python scripts/validate_docstrings.py --prefix=pandas.Time --errors=GL01,GL02
pandas.Timestamp.ctime: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.ctime: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.date: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.date: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.dst: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.dst: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.isocalendar: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.isocalendar: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.isoweekday: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.isoweekday: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.strftime: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.strftime: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.strptime: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.strptime: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.time: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.time: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.timestamp: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.timestamp: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.timetuple: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.timetuple: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.timetz: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.timetz: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.to_datetime64: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.to_datetime64: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.toordinal: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.toordinal: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.tzname: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.tzname: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.utcoffset: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.utcoffset: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.utctimetuple: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.utctimetuple: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timestamp.weekday: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timestamp.weekday: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timedelta.days: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timedelta.days: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timedelta.microseconds: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timedelta.microseconds: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
pandas.Timedelta.seconds: Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)
pandas.Timedelta.seconds: Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)

@codecov
Copy link

codecov bot commented Feb 3, 2019

Codecov Report

Merging #25118 into master will decrease coverage by 49.5%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #25118       +/-   ##
===========================================
- Coverage   92.37%   42.86%   -49.51%     
===========================================
  Files         166      166               
  Lines       52415    52415               
===========================================
- Hits        48418    22469    -25949     
- Misses       3997    29946    +25949
Flag Coverage Δ
#multiple ?
#single 42.86% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/core/categorical.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.35%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-95.46%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.17%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.15%) ⬇️
pandas/core/tools/numeric.py 10.44% <0%> (-89.56%) ⬇️
... and 123 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 800d38b...bc1fb28. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 3, 2019

Codecov Report

Merging #25118 into master will decrease coverage by 0.57%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25118      +/-   ##
==========================================
- Coverage   92.37%   91.79%   -0.58%     
==========================================
  Files         166      174       +8     
  Lines       52415    52536     +121     
==========================================
- Hits        48418    48227     -191     
- Misses       3997     4309     +312
Flag Coverage Δ
#multiple 90.35% <ø> (-0.45%) ⬇️
#single 41.87% <ø> (-1%) ⬇️
Impacted Files Coverage Δ
pandas/core/panel.py 35.53% <0%> (-62.39%) ⬇️
pandas/compat/pickle_compat.py 69.13% <0%> (-6.48%) ⬇️
pandas/plotting/_compat.py 83.33% <0%> (-4.17%) ⬇️
pandas/core/generic.py 93.54% <0%> (-3.1%) ⬇️
pandas/core/indexing.py 90.88% <0%> (-3%) ⬇️
pandas/core/ops.py 91.73% <0%> (-2.56%) ⬇️
pandas/core/groupby/ops.py 94.21% <0%> (-2.52%) ⬇️
pandas/core/config_init.py 96.96% <0%> (-2.28%) ⬇️
pandas/core/sparse/series.py 93.3% <0%> (-2.24%) ⬇️
pandas/core/internals/managers.py 93.93% <0%> (-2.14%) ⬇️
... and 123 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 800d38b...549633d. Read the comment docs.

@TomAugspurger
Copy link
Contributor

This doesn't entirely close #24070, right? Do we have a plan for the problematic inherited docstrings? Rewrite to be compliant, or add skips for those?

@TomAugspurger TomAugspurger added this to the 0.25.0 milestone Feb 3, 2019
@dcreekp
Copy link
Contributor Author

dcreekp commented Feb 3, 2019

@TomAugspurger sorry I should of mentioned I created another issue to discuss/address the situation.
#25120
I thought it would warrant another issue because fixing a problem of inherited docstrings is different to what this issue addresses.

@@ -815,28 +815,34 @@ cdef class _Timedelta(timedelta):

cpdef timedelta to_pytimedelta(_Timedelta self):
"""
return an actual datetime.timedelta object
note: we lose nanosecond resolution if any
Return an actual datetime.timedelta object.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make this an actual doc-string (e.g. have a Notes section)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback I ended up editting the whole doc-string...

Any nanosecond resolution will be lost.

Examples
--------
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure i would add all of these examples, 1 example at most and it should actually use this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback
I've made these changes: c09d83a
If there's anything else, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do these doctests pass? It looks like the whitespace formatting is off.

You may need to add a doctest: +NORMALIZE_WHITESPACE

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think any of these examples are needed, they are not showing this internal rountine. I would simply remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dcreekp as I said above I would remove all of these examples

@jreback jreback added the Timedelta Timedelta data type label Feb 6, 2019
@jreback jreback removed this from the 0.25.0 milestone Feb 6, 2019
@dcreekp dcreekp changed the title Doc fix timestamp timedelta quotes DOC: fix timestamp timedelta quotes Feb 13, 2019
@dcreekp
Copy link
Contributor Author

dcreekp commented Feb 25, 2019

@TomAugspurger @jreback
Is there anything else I need to do for this pull request to be merged? I'm asking because the point about the problematic inherited docstrings seems to be a larger issue:
#25324
One solution I could work on this:
#25120
if I know it's what people want...

@dcreekp
Copy link
Contributor Author

dcreekp commented Mar 2, 2019

@datapythonista we talked about this PR at the sprint the other day

@jreback
Copy link
Contributor

jreback commented Mar 3, 2019

@dcreekp you need to respond to comments.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Looks good, just few minor things.

For the next time, if you're working on the formatting (line breaks, capitalization...) of many docstrings, avoid working on the content of a docstring in the same PR.

It's better to review to have a whole PR of minor formatting changes, or a full docstring refactored, but not both in the same PR.

@@ -815,28 +815,63 @@ cdef class _Timedelta(timedelta):

cpdef timedelta to_pytimedelta(_Timedelta self):
"""
return an actual datetime.timedelta object
note: we lose nanosecond resolution if any
Converts a Timedelta object into a python datetime.timedelta object.
Copy link
Member

Choose a reason for hiding this comment

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

Convert instead of Converts

I think it'd be more clear: Convert a pandas Timedelta object into a python timedelta object.

--------
Converting an array of Timedeltas:

>>> arr = pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan'])
Copy link
Member

Choose a reason for hiding this comment

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

our convention is to use idx instead of arr

note: we lose nanosecond resolution if any
Converts a Timedelta object into a python datetime.timedelta object.

Timedelta objects are typecast to numpy datetime64[ns] dtype,
Copy link
Member

Choose a reason for hiding this comment

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

internally saved as instead of typecast to would wound better to me

I'd use a stop mark to separate the second sentence instead of a comma, would make this easier to read.

convert back -> convert

@dcreekp
Copy link
Contributor Author

dcreekp commented Mar 5, 2019

@datapythonista I've made changes and a comment

Any nanosecond resolution will be lost.

Examples
--------
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these doctests pass? It looks like the whitespace formatting is off.

You may need to add a doctest: +NORMALIZE_WHITESPACE


>>> idx.to_pytimedelta()
array([datetime.timedelta(1, 21901, 30), datetime.timedelta(0, 0, 16),
NaT], dtype=object)
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. to align with the d in datetime.

Copy link
Contributor Author

@dcreekp dcreekp Mar 5, 2019

Choose a reason for hiding this comment

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

$ python scripts/validate_docstrings.py pandas.Timedelta.to_pytimedelta

################################################################################
################# Docstring (pandas.Timedelta.to_pytimedelta)  #################
################################################################################

Convert a Timedelta object into a python datetime.timedelta object.

Timedelta objects are internally saved as numpy datetime64[ns] dtype.
Use to_pytimedelta() to convert to object dtype.

Returns
-------
datetime.timedelta or numpy.array of datetime.timedelta

See Also
--------
to_timedelta : Convert argument to Timedelta type.

Notes
-----
Any nanosecond resolution will be lost.

Examples
--------
>>> idx = pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan'])
>>> idx
TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015',
               NaT],
               dtype='timedelta64[ns]', freq=None)

>>> idx.to_pytimedelta()
array([datetime.timedelta(1, 21901, 30), datetime.timedelta(0, 0, 16),
NaT], dtype=object)
>>> idx[1].to_pytimedelta()
datetime.timedelta(0, 0, 16)

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

Docstring for "pandas.Timedelta.to_pytimedelta" correct. :)

It passed but I changed it to your spec.

I also found NORMALIZE_WHITESPACE in validate_docstrings.py line 517

    @property
    def examples_errors(self):
        flags = doctest.NORMALIZE_WHITESPACE | doctest.IGNORE_EXCEPTION_DETAIL
        finder = doctest.DocTestFinder()
        runner = doctest.DocTestRunner(optionflags=flags)
        ...

@TomAugspurger

Any nanosecond resolution will be lost.

Examples
--------
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think any of these examples are needed, they are not showing this internal rountine. I would simply remove them.

@dcreekp
Copy link
Contributor Author

dcreekp commented Mar 11, 2019

I just want to clarify; the docstings is for this function cpdef timedelta to_pytimedelta(_Timedelta self) and in the example I have:

>>> idx.to_pytimedelta()

and

>>> idx[1].to_pytimedelta()

am I not using it?? @jreback

Any nanosecond resolution will be lost.

Examples
--------
Copy link
Contributor

Choose a reason for hiding this comment

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

@dcreekp as I said above I would remove all of these examples

@dcreekp
Copy link
Contributor Author

dcreekp commented Mar 29, 2019

@jreback deleted.
curious what you would have instead though...

@jreback jreback added this to the 0.25.0 milestone Mar 30, 2019
@jreback jreback merged commit d95b306 into pandas-dev:master Mar 30, 2019
@jreback
Copy link
Contributor

jreback commented Mar 30, 2019

thanks @dcreekp

to_pytimedelta is a compatibilty routine and IMHO a trivial funciton, so examples are overkill.

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

Successfully merging this pull request may close these issues.

DOC: Fix quotes position in Timestamp and Timedelta
4 participants