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

ENH: Add accessor for isocalendar returning iso year, week, and day #33206

Closed
mgmarino opened this issue Apr 1, 2020 · 1 comment · Fixed by #33220
Closed

ENH: Add accessor for isocalendar returning iso year, week, and day #33206

mgmarino opened this issue Apr 1, 2020 · 1 comment · Fixed by #33220
Labels
Datetime Datetime data dtype Enhancement
Milestone

Comments

@mgmarino
Copy link
Contributor

mgmarino commented Apr 1, 2020

This enhancement request is to add an accessor to DatetimeProperties for the ISO year, which is the year corresponding to the week calculated via ISO 8601.

Currently, we can access the ISO week via week and weekofyear, and Timestamp objects provide isocalendar, which returns the correct ISO year, week, and day.

Examples

For example:

df = pandas.DataFrame()

df["event_date"] = ["2020-01-01", "2019-12-31"]
df["event_date"] = df.event_date.astype("datetime64[D]")

df.event_date.dt.weekofyear.values, df.event_date.dt.year.values

outputs:

(array([1, 1]), array([2020, 2019]))

and accessing the Timestamp objects

df.event_date[0].isocalendar(), df.event_date[1].isocalendar()

yields

((2020, 1, 3), (2020, 1, 2))

It would be great to have an accessor to get access this isocalendar year value for a series, e.g.:

df.event_date.dt.year_for_weekofyear.values
array([2020, 2020])

or maybe even better to have an isocalendar accessor where the same iso values are available like in Timestamp.isocalendar, e.g.

df.event_date.dt.isocalendar.values
array([[2020, 1, 3], [2020, 1, 2]]))

I am happy to try a PR here, but some input would be great as to:

  • which direction to proceed
  • naming, etc.
@mgmarino
Copy link
Contributor Author

mgmarino commented Apr 3, 2020

As a result of discussions in #33220, we decided to add an isocalendar accessor. For more details, see the comment thread there. I will update this issue accordingly.

@mgmarino mgmarino changed the title ENH: Include accessor for ISO year (corresponding to weekofyear) ENH: Add accessor for isocalendar returning iso year, week, and day Apr 3, 2020
@jreback jreback added this to the 1.1 milestone Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants