Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: undeprecate and update num2epoch/epoch2num #17983

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 1 commit into from
Jul 21, 2020

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jul 20, 2020

PR Summary

#15008 added a new variable epoch.

At the time I did not update the unfortunately named epoch2num and num2epoch because Matplotlib does not use these. They are also ill-named because in this case epoch refers to a UNIX-like time of seconds since 1970-01-01, and thats not at all what an epoch is. We also deprecated these functions at the time.

Unfortunately pandas uses them, and they need to be made compatible with the new epoch handling. pandas-dev/pandas#35350 and pandas-dev/pandas#34850

Here I've updated those functions to work with the variable epoch, and removed the deprecation, and added a test for the basic functionality with both the old and new epoch.

On the pandas side,

import datetime
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter

from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

t = [
    datetime.datetime(2022, 12, 31, 0, 0),
    datetime.datetime(2022, 11, 30, 0, 0),
    datetime.datetime(2022, 10, 31, 0, 0),
]
s = [0.0, 0.1, 0.2]

fig, ax = plt.subplots()
ax.plot_date(x=t, y=s)
ax.xaxis.set_major_formatter(DateFormatter("%b '%y"))

plt.xticks(rotation=90)
plt.show()

is fixed, with no further work on their side needed.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

@jklymak jklymak added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: date handling labels Jul 20, 2020
@jklymak jklymak added this to the v3.3.1 milestone Jul 20, 2020
@jklymak
Copy link
Member Author

jklymak commented Jul 20, 2020

Marking as release critical - this will break anyone using pandas date converter and Matplotlib 3.0.

@tacaswell
Copy link
Member

Do we need to pull back notes in API changes too?

@jklymak
Copy link
Member Author

jklymak commented Jul 20, 2020

Probably, unless we wanted to soft un-deprecate it 😉 I don't think we should be maintaining a second floating-point date representation. Looking at pandas, I think they don't need the call any more either since we have supported datetime64 for quite while....

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Blocking on updating API change note.

@jklymak jklymak force-pushed the fix-pandas-need-num2epoch branch from 1487765 to 52528fe Compare July 20, 2020 23:08
@jklymak jklymak force-pushed the fix-pandas-need-num2epoch branch from 52528fe to 32ef145 Compare July 20, 2020 23:08
@QuLogic QuLogic merged commit 57c8baa into matplotlib:master Jul 21, 2020
@lumberbot-app
Copy link

lumberbot-app bot commented Jul 21, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.3.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 57c8baaf85f0cfd44a27ef834dc971128b7f8ee4
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #17983: FIX: undeprecate and update num2epoch/epoch2num'
  1. Push to a named branch :
git push YOURFORK v3.3.x:auto-backport-of-pr-17983-on-v3.3.x
  1. Create a PR against branch v3.3.x, I would have named this PR:

"Backport PR #17983 on branch v3.3.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@jklymak
Copy link
Member Author

jklymak commented Jul 21, 2020

OK, this is upset because 3.3.x is not tracking doc/api/next_api_changes/deprecations/. Where should the un-deprecation notice go? And if it goes in 3.3.x, should the notice be removed from master?

@tacaswell
Copy link
Member

In the past we have added sections to the top of the minor version API changes page for the patch-release back-tracking on the deprecation (or had to retro-actively document accidentally API changes).

jklymak pushed a commit to jklymak/matplotlib that referenced this pull request Jul 21, 2020
…epoch

FIX: undeprecate and update num2epoch/epoch2num
jklymak added a commit to jklymak/matplotlib that referenced this pull request Jul 21, 2020
jklymak added a commit to jklymak/matplotlib that referenced this pull request Jul 21, 2020
@jklymak jklymak deleted the fix-pandas-need-num2epoch branch July 21, 2020 05:02
@QuLogic QuLogic mentioned this pull request Aug 14, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: date handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants