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

BUG: Breaking change to offsets.pyx - quarter offset classes #39890

Closed
wants to merge 69 commits into from

Conversation

Pawel-Kranzberg
Copy link
Contributor

@Pawel-Kranzberg Pawel-Kranzberg commented Feb 18, 2021

Set default months for BQuarterEnd, BQuarterBegin, QuarterEnd, QuarterBegin classes in order; rename startingMonth parameter to month for those classes.
Addresses #8435 and #5307

@jreback
Copy link
Contributor

jreback commented Feb 18, 2021

pls just one PR - just push to the same one if changing

@Pawel-Kranzberg
Copy link
Contributor Author

Pawel-Kranzberg commented Feb 18, 2021

pls just one PR - just push to the same one if changing

But this one has different scope from #39887 . The change regarding months alone in #39887 should hopefully be easier to process, and less breaking.

@jreback
Copy link
Contributor

jreback commented Feb 18, 2021

ok that's fine

you always need a test

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.

you would need to change / add tests to show what is changing. and have the tests pass

@jreback jreback added the Frequency DateOffsets label Feb 19, 2021
@jbrockmendel
Copy link
Member

does this handle #5307?

@Pawel-Kranzberg
Copy link
Contributor Author

does this handle #5307?

Not at present. I'd like to cover it as well - please let me know if that's OK.

@Pawel-Kranzberg
Copy link
Contributor Author

does this handle #5307?

It does now.

@Pawel-Kranzberg
Copy link
Contributor Author

can you add a sub-section in the whatsnew 1.3 api breaking changes to indicate what a user would except (aside from the deprection)

Description drafted and added.

@Pawel-Kranzberg
Copy link
Contributor Author

so you are adding a new parameter 'month', so now we have the confusing 'startingMonth' and 'month'. I would rather deprecate 'startingMonth', then add new; not even sure 'month' is a good name here. can you write a sample whatsnew note indicate what the change is here from a user POV.

BTW, maybe anchor would be a better replacement name?

Quarter-based time offset classes :class:`~pandas.tseries.offsets.QuarterEnd`,
:class:`~pandas.tseries.offsets.QuarterBegin`, :class:`~pandas.tseries.offsets.BQuarterEnd`,
:class:`~pandas.tseries.offsets.BQuarterBegin` now use ``month`` instead of ``startingMonth``
as a time anchor parameter (:issue:`5307`). Its default value for :class:`~pandas.tseries.offsets.QuarterBegin`
Copy link
Member

Choose a reason for hiding this comment

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

"Its" -> "The"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed.


def __init__(self, n=1, normalize=False, startingMonth=None):
def __init__(self, n: int=1, normalize: bool=False, month: int=None,
*, startingMonth: int=None): # GH#5307 backwards compatibility
Copy link
Member

Choose a reason for hiding this comment

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

comment on new line # GH#5307 startingMonth retained for backwards compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added.


def __init__(self, n=1, normalize=False, startingMonth=None):
def __init__(self, n: int=1, normalize: bool=False, month: int=None,
Copy link
Member

Choose a reason for hiding this comment

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

should we try to detect if month is passed as a non-keyword, in which case the behavior may be silently changing?

(if backward compat werent an issue, I'd be OK with making everything other than n and normalize keyword-only in all these classes)

raise TypeError("Offset received both month and startingMonth")
elif month is None and startingMonth is not None:
warnings.warn(
"startingMonth is deprecated, use month instead.",
Copy link
Member

Choose a reason for hiding this comment

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

should this explain that the meaning has changed? or point to a link?

warnings.warn(
"startingMonth is deprecated, use month instead.",
FutureWarning,
stacklevel=2
Copy link
Member

Choose a reason for hiding this comment

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

trailing comma, pretend we could run black on this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, hopefully.

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.

@Pawel-Kranzberg can you split this change up. There is just too much going on here.

  • doc-strings
  • deprecation
  • breaking change

I would really like to do the deprecation first and separate

@@ -458,6 +458,36 @@ with a :class:`MultiIndex` in the result. This can lead to a perceived duplicati
df.groupby('label1').rolling(1).sum()


.. _whatsnew_130.notable_bug_fixes.quarterbegin_default_anchor:

Changed default periods in :class:`~pandas.tseries.offsets.QuarterBegin` and :class:`~pandas.tseries.offsets.BQuarterBegin`
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be the same length as the title, it should error if not


*pandas 1.3.0*

.. code-block:: ipython
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use a code-block, rather an ipython block for the new behavior

@@ -458,6 +458,36 @@ with a :class:`MultiIndex` in the result. This can lead to a perceived duplicati
df.groupby('label1').rolling(1).sum()


.. _whatsnew_130.notable_bug_fixes.quarterbegin_default_anchor:
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to say deprecation about the startingMonth as its mentioned below as well. I would prefer making these 2 distinct and unrelated changes (which they are). so don't mention deprecation at all here.

@@ -625,6 +656,7 @@ Datetimelike
- Bug in :meth:`Timedelta.round`, :meth:`Timedelta.floor`, :meth:`Timedelta.ceil` for values near the implementation bounds of :class:`Timedelta` (:issue:`38964`)
- Bug in :func:`date_range` incorrectly creating :class:`DatetimeIndex` containing ``NaT`` instead of raising ``OutOfBoundsDatetime`` in corner cases (:issue:`24124`)
- Bug in :func:`infer_freq` incorrectly fails to infer 'H' frequency of :class:`DatetimeIndex` if the latter has a timezone and crosses DST boundaries (:issue:`39556`)
- Bug in offsets :class:`QuarterBegin` and :class:`BQuarterBegin` returning days that are not conventional quarter beginnings (:issue:`8435`)
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this a duplicate of the above section?

startingMonth = self._default_starting_month
self.startingMonth = startingMonth
# GH#5307 startingMonth retained for backwards compatibility
if month and startingMonth and month != startingMonth:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need to check not-none? e.g. 0 is value that would hit this too (which would fail but is misleading no?)

self.startingMonth = state.pop("startingMonth")
try:
self.month = state.pop("month")
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this is non-obvious on the exception.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2021

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 Jun 9, 2021
@Pawel-Kranzberg Pawel-Kranzberg marked this pull request as draft June 10, 2021 17:02
@simonjayhawkins
Copy link
Member

I would really like to do the deprecation first and separate

@Pawel-Kranzberg what's the status. close this and open separate PRs?

@Pawel-Kranzberg
Copy link
Contributor Author

I would really like to do the deprecation first and separate

@Pawel-Kranzberg what's the status. close this and open separate PRs?

Yes, I plan to do so next week.

@mroeschke
Copy link
Member

Thanks for the PR, but it has appeared to have gone stale. Closing due to inactivity, but we would be happy to take a new PR working on the deprecation first.

@mroeschke mroeschke closed this Aug 17, 2021
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.

DEPR: QuarterBegin and BQuarterBegin return days that are not quarter beginnings
6 participants