Skip to content

BUG: don't cache pandas matplotlib converters (#27036) #27968

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ def register(explicit=True):
converter = cls()
if type_ in units.registry:
previous = units.registry[type_]
_mpl_units[type_] = previous
# Exclude our converters from caching to make this idempotent.
if type(previous) not in {
Copy link
Member

Choose a reason for hiding this comment

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

the preferred way to do this check would be if not isinstance(previous, ...)

Copy link
Member

Choose a reason for hiding this comment

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

... though now that i look below, it looks like someone else used this pattern before, so never mind

DatetimeConverter,
PeriodConverter,
TimeConverter,
}:
_mpl_units[type_] = previous
units.registry[type_] = converter


Expand All @@ -80,9 +86,7 @@ def deregister():

# restore the old keys
for unit, formatter in _mpl_units.items():
if type(formatter) not in {DatetimeConverter, PeriodConverter, TimeConverter}:
# make it idempotent by excluding ours.
units.registry[unit] = formatter
units.registry[unit] = formatter


def _check_implicitly_registered():
Expand Down