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: Correct inconsistent description on default DateOffset setting #36516

Merged
merged 12 commits into from
Oct 31, 2020
Merged

DOC: Correct inconsistent description on default DateOffset setting #36516

merged 12 commits into from
Oct 31, 2020

Conversation

GYHHAHA
Copy link
Contributor

@GYHHAHA GYHHAHA commented Sep 21, 2020

correct inconsistent doc description on default DateOffset setting

correct inconsistent doc description on default DateOffset setting
Copy link
Member

@arw2019 arw2019 left a comment

Choose a reason for hiding this comment

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

thanks @GYHHAHA

doc/source/user_guide/timeseries.rst Outdated Show resolved Hide resolved
@arw2019
Copy link
Member

arw2019 commented Sep 21, 2020

Also heads up there are linting issues

##[error]doc/source/user_guide/timeseries.rst:834:83:E501:line too long (105 > 79 characters)

to be resolved before merge

remove the example for DateOffset default setting
@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 21, 2020

why fail and how can I fix?

@MarcoGorelli
Copy link
Member

What's wrong with "one calendar day"?

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 21, 2020

>>>ts = pd.Timestamp('2011-3-27 00:00:00', tz='Europe/Helsinki')

One calendar day will get the result below.

>>>ts + pd.DateOffset(days=1)
Timestamp('2011-03-28 00:00:00+0300', tz='Europe/Helsinki')

But now the default action is add absolute 24 hours.

>>>ts + pd.DateOffset()
Timestamp('2011-03-28 01:00:00+0300', tz='Europe/Helsinki')
>>>ts + pd.DateOffset(hours=24)
Timestamp('2011-03-28 01:00:00+0300', tz='Europe/Helsinki')

@MarcoGorelli
Copy link
Member

Ah, thanks!

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 21, 2020

So how can I fix these failings? Seems that I only change one line.

@MarcoGorelli
Copy link
Member

They're unrelated, you'll probably need to merge upstream/master later

@@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ
:header: "Date Offset", "Frequency String", "Description"
:widths: 15, 15, 65

:class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 1 calendar day"
:class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 24 hours"
Copy link
Contributor

Choose a reason for hiding this comment

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

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 21, 2020

But still a little strange about the default value, why not just set it a calendar day since the offset objects are specially designed for calendar duration rules?

@mroeschke
Copy link
Member

I think this should ideally default to calendar day instead 24 hours as well. This would require a deprecation cycle related to #7418 that would deprecate all arguments that don't end with s.

Would you be interested in making that change instead @GYHHAHA?

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 22, 2020

I will take a try.

Change the default setting for DateOffset to a calendar day.
add a test for dateoffset default value
@pep8speaks
Copy link

pep8speaks commented Sep 22, 2020

Hello @GYHHAHA! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 172:1: W293 blank line contains whitespace

Comment last updated at 2020-09-22 06:42:18 UTC

change doc to original description
resolve PEP 8 issues
@GYHHAHA GYHHAHA changed the title Update timeseries.rst Change default setting for DateOffset to a calendar day Sep 22, 2020
@jreback jreback added the Frequency DateOffsets label Sep 22, 2020
@@ -319,7 +319,8 @@ cdef _determine_offset(kwds):
# sub-daily offset - use timedelta (tz-aware)
offset = timedelta(**kwds_no_nanos)
else:
offset = timedelta(1)
offset = relativedelta(**{'days':1})
Copy link
Contributor

Choose a reason for hiding this comment

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

@mroeschke I don't know how we can easily deprecate this, nor can we simply change this.

Copy link
Member

Choose a reason for hiding this comment

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

Can't simply change this in the next release, but I think we could deprecate the keyword arguments and slate for removal in 2.0.

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 22, 2020

For #7418, can we just convert any argument in kwds_no_nanos that end with s to the one with s? @jreback

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 22, 2020

Also since the _determine_offset doesn't handle the nanosecond or nanoseconds, thus here is a bug related to this.

>>>ts = pd.Timestamp('2020-1-1')
>>>ts + pd.DateOffset(nanoseconds=1000)
Timestamp('2020-01-02 00:00:00')

Caused by the default offset = timedelta(1) setting. @mroeschke

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 23, 2020

Ok, I will keep this in original form, and should I continue to change the "1 calendar day" to "24 hours" in the DOC?

  1. Maybe a warning need to be added when use singular arguments.
  2. I find in DOC: hour/hours (and other plurals) based on dateutil.relativedelta #7418 ts.replace(pd.DateOffset(...)) is suggested, is this a good way to make these replacement actions?
  3. The above-mentioned nanoseconds BUG needs a fix, but since this relates to the default setting, will it be troublesome to handle?

Thanks. @jreback @mroeschke

@mroeschke
Copy link
Member

Yes I think for this PR, you can just make the documentation change.

You can follow up with another PR to deprecate the DateOffset arguments that do not end in s if interested.

Also if you could submit a bug report with the nanosecond example, that'd be great.

@GYHHAHA GYHHAHA changed the title Change default setting for DateOffset to a calendar day DOC: Correct inconsistent description on default DateOffset setting Sep 24, 2020
@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 24, 2020

Here are also some problems.

DOC says "However, all DateOffset subclasses that are an hour or smaller (Hour, Minute, Second, Milli, Micro, Nano) behave like Timedelta and respect absolute time.".

But though DateOffset(days=1) indeed use a calendar day, still offsets.Day(1) use 24 absolute hours.

Is it necessary to keep this consistency?

Besides, in #36592 I suggest to add replace method for time-related replacement, but now I also think it may not be a good choice.

However, we can only use ts + pd.DateOffset(day=5) to change the absolute year/day/hour/... use the singular form argument which will be deprecated (if we make this deprecation), thus how can we do this absolute time replacement by other offsets object? (like changing year to 2000 or day to 22 or month to 5)

Thanks! @mroeschke

@mroeschke
Copy link
Member

See #22864 about the offsets.Day consistency.

For absolute time changes, I think users should just stick to using Timedelta objects. DateOffset object should only operate with relative time changes.

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Sep 24, 2020

agree with jbrockmendel

If we're talking reasonably long-term, I think we should get rid of the Tick classes entirely and use Timedelta in their place

It will be much more clear to only consider the relative time (day, week, month ,year, ...) for offsets and tick time (nano, ..., minute, hour, absolute day) for timedelta.

@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 Oct 27, 2020
@jreback jreback added this to the 1.2 milestone Oct 31, 2020
@jreback jreback added Docs and removed Stale labels Oct 31, 2020
@jreback
Copy link
Contributor

jreback commented Oct 31, 2020

@mroeschke this lgtu?

@mroeschke mroeschke merged commit 10de71c into pandas-dev:master Oct 31, 2020
@mroeschke
Copy link
Member

Thanks @GYHHAHA

@GYHHAHA GYHHAHA deleted the patch-1 branch October 31, 2020 23:50
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
…andas-dev#36516)

* Update timeseries.rst

correct inconsistent doc description on default DateOffset setting

* Update timeseries.rst

remove the example for DateOffset default setting

* Update offsets.pyx

Change the default setting for DateOffset to a calendar day.

* Update test_liboffsets.py

add a test for dateoffset default value

* Update timeseries.rst

change doc to original description

* Update test_liboffsets.py

resolve PEP 8 issues

* Update timeseries.rst

* Update test_liboffsets.py

* Update offsets.pyx

* Change default Offset setting description in DOC

* Update timeseries.rst

* Update timeseries.rst
ukarroum pushed a commit to ukarroum/pandas that referenced this pull request Nov 2, 2020
…andas-dev#36516)

* Update timeseries.rst

correct inconsistent doc description on default DateOffset setting

* Update timeseries.rst

remove the example for DateOffset default setting

* Update offsets.pyx

Change the default setting for DateOffset to a calendar day.

* Update test_liboffsets.py

add a test for dateoffset default value

* Update timeseries.rst

change doc to original description

* Update test_liboffsets.py

resolve PEP 8 issues

* Update timeseries.rst

* Update test_liboffsets.py

* Update offsets.pyx

* Change default Offset setting description in DOC

* Update timeseries.rst

* Update timeseries.rst
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.

DOC: default value for pd.DateOffset() is 24 hours instead of 1 calendar day
6 participants