Skip to content

DOC: Fixing EX01 - Added examples #53689

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 10 commits into from
Jun 20, 2023

Conversation

DeaMariaLeon
Copy link
Member

Towards #37875

Partially fixing #53668

@DeaMariaLeon DeaMariaLeon added this to the 2.1 milestone Jun 15, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @DeaMariaLeon !

Would be good to add a little test for these - could just add them to

def test_negative_dates():
# https://github.com/pandas-dev/pandas/issues/50787
ts = Timestamp("-2000-01-01")
msg = (
"^strftime not yet supported on Timestamps which are outside the range of "
"Python's standard library. For now, please call the components you need "
r"\(such as `.year` and `.month`\) and construct your string from there.$"
)
with pytest.raises(NotImplementedError, match=msg):
ts.strftime("%Y")

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

really sorry, noticed a few more things, so I'm "requesting changes" again

we should also add a whatsnew note to the 2.1.0.rst bug fixes section, noting that Timestamp.date was returning incorrect results for inputs outside those supported by the Python standard library's datetime module

Comment on lines 1554 to 1555
"For now, please call the components you need (such as `.year` "
"and `.month`) and construct your string from there."
Copy link
Member

Choose a reason for hiding this comment

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

we're not constructing a string, so we can remove this part of the message


def dst(self):
"""
Return self.tzinfo.dst(self).
Copy link
Member

Choose a reason for hiding this comment

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

How about

Return the daylight saving time (DST) adjustment.

Comment on lines 1565 to 1568
>>> ts = pd.Timestamp('2000-06-01 00:00:00',
... tz='Europe/Brussels').dst()
>>> ts
datetime.timedelta(seconds=3600)
Copy link
Member

Choose a reason for hiding this comment

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

ts usually means "timestamp", so maybe let's do

>>> ts = pd.Timestamp('2000-06-01 00:00:00', tz='Europe/Brussels')
>>> ts.dst()
datetime.timedelta(seconds=3600)

Comment on lines 1570 to 1573
_dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond, self.tzinfo, fold=self.fold)
return _dt.dst()
Copy link
Member

@MarcoGorelli MarcoGorelli Jun 19, 2023

Choose a reason for hiding this comment

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

looks like we're not catching anything here, so can we just return return super().dst()?

maybe we can do the same for the others where we're just overriding the docstrings, like
EDIT: please disregard the second half of this message, only the first sentence (above) makes sense

Comment on lines 1546 to 1549
try:
_dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond, self.tzinfo, fold=self.fold)
Copy link
Member

@MarcoGorelli MarcoGorelli Jun 19, 2023

Choose a reason for hiding this comment

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

can we construct a date object directly, and then return that? like

_dt = date(self.year, self.month, self.day)

, where date is imported from datetime?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the corrections. :)
I did all of them locally except this one. I can't find how to import date from datetime without breaking it.

Copy link
Member

Choose a reason for hiding this comment

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

might work to do import datetime as dt, then use dt.date

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

sorry one more comment (in any case, CI needs fixing, but hopefully #53730 and
#53727 will do that)

Comment on lines 2390 to 2467
return self.weekday() + 1
try:
_dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond, self.tzinfo, fold=self.fold)
except ValueError as err:
raise NotImplementedError(
"isoweekday not yet supported on Timestamps which "
"are outside the range of Python's standard library. "
) from err
return _dt.weekday() + 1
Copy link
Member

Choose a reason for hiding this comment

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

wait sorry, why did this one have to change? isn't self.weekday() + 1 correct?

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 thought that if we give it a negative date it should raise. So, in the stable version:
for ts = pd.Timestamp('-2000') the output is:
ts.isoweekday()=7
ts.weekday()=6

Comment on lines 1145 to 1147
func = "^isoweekday"
with pytest.raises(NotImplementedError, match=func + msg):
ts.isoweekday()
Copy link
Member

Choose a reason for hiding this comment

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

see my comment above, not sure this one needs to raise?

Copy link
Member Author

Choose a reason for hiding this comment

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

Please see my question above.

@@ -350,6 +350,7 @@ Datetimelike
^^^^^^^^^^^^
- :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
- Bug in :func:`date_range` when ``freq`` was a :class:`DateOffset` with ``nanoseconds`` (:issue:`46877`)
- Bug in :meth:`Timestamp.date`, :meth:`Timestamp.isocalendar`, and :meth:`Timestamp.isoweekday` were returning incorrect results for inputs outside those supported by the Python standard library's datetime module (:issue:`53668`)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove isoweekday

Copy link
Member Author

Choose a reason for hiding this comment

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

Requested changes done.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

nice, should be good now - thanks @DeaMariaLeon !

@MarcoGorelli MarcoGorelli merged commit 8cf7ac1 into pandas-dev:main Jun 20, 2023
@DeaMariaLeon DeaMariaLeon deleted the examples-Jun13 branch June 20, 2023 16:45
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
* Added Timestamp examples

* Added test and corrected msg

* Correcting error on isoweekday

* Added requested corrections

* added import datetime

* Removed isoweekday raise error, corrected time and timetz
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.

2 participants