Skip to content
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

DOC: Timestamp EX01 errors #37904

Merged
merged 33 commits into from
Apr 30, 2021

Conversation

lucasrodes
Copy link
Contributor

@lucasrodes lucasrodes commented Nov 16, 2020

Example section added for several methods in class pd.Timestamp


Examples added for:

  • pandas.Timestamp.asm8
  • pandas.Timestamp.day_of_week
  • pandas.Timestamp.day_of_year
  • pandas.Timestamp.days_in_month
  • pandas.Timestamp.is_leap_year
  • pandas.Timestamp.is_month_end
  • pandas.Timestamp.is_month_start
  • pandas.Timestamp.is_quarter_end
  • pandas.Timestamp.is_quarter_start
  • pandas.Timestamp.is_year_end
  • pandas.Timestamp.is_year_start
  • pandas.Timestamp.quarter
  • pandas.Timestamp.tz
  • pandas.Timestamp.week
  • pandas.Timestamp.ceil
  • pandas.Timestamp.combine
  • pandas.Timestamp.day_name
  • pandas.Timestamp.floor
  • pandas.Timestamp.fromordinal
  • pandas.Timestamp.fromtimestamp
  • pandas.Timestamp.month_name
  • pandas.Timestamp.normalize
  • pandas.Timestamp.now
  • pandas.Timestamp.replace
  • pandas.Timestamp.round
  • pandas.Timestamp.strftime
  • pandas.Timestamp.timestamp
  • pandas.Timestamp.to_numpy
  • pandas.Timestamp.to_julian_date
  • pandas.Timestamp.to_period
  • pandas.Timestamp.to_pydatetime
  • pandas.Timestamp.today
  • pandas.Timestamp.tz_convert
  • pandas.Timestamp.tz_localize
  • pandas.Timestamp.utcfromtimestamp
  • pandas.Timestamp.utcnow
  • pandas.Timestamp.weekday

@lucasrodes lucasrodes changed the title Feature/docstrings errors DOC: Timestamp EX01 errors Nov 16, 2020
@lucasrodes
Copy link
Contributor Author

From the checks, I believe that there are some docstrings that were not supposed to be changed?

I am starting to contribute and trying to follow up on this #17327

Copy link
Contributor

@jreback jreback 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 a couple of comments. pls merge master and ping on green.

pandas/_libs/tslibs/timestamps.pyx Show resolved Hide resolved
pandas/_libs/tslibs/timestamps.pyx Show resolved Hide resolved
pandas/_libs/tslibs/timestamps.pyx Show resolved Hide resolved
Timestamp('2020-03-14 15:32:00')
>>> ts.floor(freq='S') # seconds
Timestamp('2020-03-14 15:32:52')
>>> ts.floor(freq='L') # miliseconds
Copy link
Contributor

Choose a reason for hiding this comment

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

prob can show just a few rather than all

pandas/_libs/tslibs/timestamps.pyx Show resolved Hide resolved
@jreback jreback added Docs Datetime Datetime data dtype labels Nov 19, 2020
@jreback
Copy link
Contributor

jreback commented Nov 20, 2020

can you merge master and ping on green (to make sure no failures are real).

@lucasrodes
Copy link
Contributor Author

lucasrodes commented Nov 20, 2020

Added few changes to pandas/_libs/tslibs/nattype.pyx so the docstrings match (this check is done by test attached below). Should pass the tests now, I'll ping you once the checks finish.

def test_nat_doc_strings(compare):

@lucasrodes
Copy link
Contributor Author

@jreback changes reverted

@jreback
Copy link
Contributor

jreback commented Nov 25, 2020

Sure @jreback, can do that. However, this pull request won't go through the tests as I mentioned before (won't be green). Should we merge it regardless?

oh how is master passing now then?

yeah this needs to be green. ok i guess re-revert. the only thing with the NaT tests is that they should be showing NaT int he examples

@lucasrodes
Copy link
Contributor Author

Hi @jreback ,
The test I attach below is checking if the docstrings between methods in pandas/_libs/tslibs/nattype.pyx and pandas/_libs/tslibs/timestamps.pyx match. That's why I also used pd.Timestamp instead of pd.NaT.

def test_nat_doc_strings(compare):

Should we maybe change the test pandas/pandas/tests/scalar/test_nat.py in onther PR?

@jreback
Copy link
Contributor

jreback commented Nov 26, 2020

Hi @jreback ,
The test I attach below is checking if the docstrings between methods in pandas/_libs/tslibs/nattype.pyx and pandas/_libs/tslibs/timestamps.pyx match. That's why I also used pd.Timestamp instead of pd.NaT.

def test_nat_doc_strings(compare):

Should we maybe change the test pandas/pandas/tests/scalar/test_nat.py in onther PR?

ok instead let's use the same doc-string, BUT add a NaT example to it, this should make tests pass and make the examples useful.

ping on green.

@lucasrodes
Copy link
Contributor Author

Error in the following test from pandas/tests/io/test_gcs.py in Windows. Not sure what is causing it.

def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding):
"""
Compression and encoding should with GCS.
GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
GH 32392 (read_csv, encoding)
"""
from fsspec import registry
registry.target.clear() # remove state
df = tm.makeDataFrame()
# reference of compressed and encoded file
compression = {"method": compression_only}
if compression_only == "gzip":
compression["mtime"] = 1 # be reproducible
buffer = BytesIO()
df.to_csv(buffer, compression=compression, encoding=encoding, mode="wb")
# write compressed file with explicit compression
path_gcs = "gs://test/test.csv"
df.to_csv(path_gcs, compression=compression, encoding=encoding)
assert gcs_buffer.getvalue() == buffer.getvalue()
read_df = read_csv(
path_gcs, index_col=0, compression=compression_only, encoding=encoding
)
tm.assert_frame_equal(df, read_df)
# write compressed file with implicit compression
if compression_only == "gzip":
compression_only = "gz"
compression["method"] = "infer"
path_gcs += f".{compression_only}"
df.to_csv(path_gcs, compression=compression, encoding=encoding)
assert gcs_buffer.getvalue() == buffer.getvalue()
read_df = read_csv(path_gcs, index_col=0, compression="infer", encoding=encoding)
tm.assert_frame_equal(df, read_df)

@lucasrodes
Copy link
Contributor Author

On another note:

Hi @jreback, thanks for your feedback.

Let me summarize last commits below.

1) NaT examples added

I have added examples with NaT in the docstrings of the following functions in nattype.pyx and timestamps.pyx:

  • tz_convert
  • tz_localize
  • today
  • to_pydatetime
  • to_numpy
  • round
  • replace
  • now
  • month_name
  • floor
  • day_name
  • ceil

Hence, these methods now have the same docstring in both modules and should pass the tests ✔️.

2) NaT examples not added

Next, I have not added NaT examples in the following examples as these methods basically raise a ValueError if called from a NaT object. However I have copied the docstrings from timestamps.pyx (otherwise tests are not passed).

  • utcnow
  • utcfromtimestamp
  • timestamp
  • strftime
  • fromtimestamp
  • fromordinal
  • combine
  • astimezone

Note that these methods were created using method _make_error_func instead of _make_nat_func or _make_nan_func.

As these methods now have the same docstring in both modules and should pass the tests ✔️.


3) Way forward

From here I see three ways out:

A) Review of this PR, iterate and merge.
B) Remove the Example section from all methods listed in 2) in both modules (so docstrings still match), commit, review and merge PR.
C) Review the tests in test_nat.pyx. In particular the parametrization of compare. Probably another PR is required.

@pytest.mark.parametrize(
"compare",
(
_get_overlap_public_nat_methods(Timestamp, True)
+ _get_overlap_public_nat_methods(Timedelta, True)
),
)
def test_nat_doc_strings(compare):
# see gh-17327
#
# The docstrings for overlapping methods should match.
klass, method = compare
klass_doc = getattr(klass, method).__doc__
nat_doc = getattr(NaT, method).__doc__
assert klass_doc == nat_doc

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Dec 28, 2020
@jreback
Copy link
Contributor

jreback commented Dec 28, 2020

@lucasrodes i am ok prob merging this as is, if you can merge master and ping

@jreback
Copy link
Contributor

jreback commented Feb 11, 2021

@lucasrodes this was close. if you can merge master and see if can get all passing.

@lucasrodes
Copy link
Contributor Author

Sorry for the late reply @jreback. Will do asap

@lucasrodes
Copy link
Contributor Author

@jreback merged with master

Add 'Europe/Stockholm' as timezone:

>>> ts.tz_localize(tz='Europe/Stockholm')
Timestamp('2020-03-14 15:32:52.192548651+0100', tz='Europe/Stockholm'
Copy link
Member

Choose a reason for hiding this comment

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

Missing an ending )

@mroeschke mroeschke removed the Stale label Mar 21, 2021
@mroeschke
Copy link
Member

Sorry for the long delay @lucasrodes . Looks mostly good. One comment otherwise LGTM

@lucasrodes
Copy link
Contributor Author

@mroeschke Merged with upstream & fixed typos (missing '(' in docstring examples)

@mroeschke mroeschke added this to the 1.3 milestone Mar 21, 2021
@mroeschke mroeschke merged commit 0acbff8 into pandas-dev:master Apr 30, 2021
@mroeschke
Copy link
Member

Thanks @lucasrodes! Apologies for the long wait getting this one in.

yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
* SS01 errors fixed

* trailing-whitespace error fixed

* added coded to code_checks.sh script

* fixed docstrings consistency

* mistaken file

* trailing-whitespace typo

* Example section for ceil method

* Added example section for ceil, floor and round

* example section added to methods day_name, month_name, fromordinal, utcfromtimestamp, fromtimestamp, combine. Typos in ceil, round, floor corrected

* trailing whitespace

* typo in floor method

* added example section for method normalize

* typo

* recommendations from pull request review

* typo

* revert changes. to be addressed in another PR

* Added NaT examples in nattype and timestamp docstrings where needed.

* trigger GitHub actions

* added missing ( in docstring examples

* added missing ( in docstring example

Co-authored-by: lucasrodes <lucasrodesg@gmail.com>
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
* SS01 errors fixed

* trailing-whitespace error fixed

* added coded to code_checks.sh script

* fixed docstrings consistency

* mistaken file

* trailing-whitespace typo

* Example section for ceil method

* Added example section for ceil, floor and round

* example section added to methods day_name, month_name, fromordinal, utcfromtimestamp, fromtimestamp, combine. Typos in ceil, round, floor corrected

* trailing whitespace

* typo in floor method

* added example section for method normalize

* typo

* recommendations from pull request review

* typo

* revert changes. to be addressed in another PR

* Added NaT examples in nattype and timestamp docstrings where needed.

* trigger GitHub actions

* added missing ( in docstring examples

* added missing ( in docstring example

Co-authored-by: lucasrodes <lucasrodesg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants