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

Skip to content

Deprecate old and little used formatters. #16170

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
Jan 12, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,12 @@ and containment checks) via `.Line2D.set_picker` is deprecated. Use
The ``on_mappable_changed`` and ``update_bruteforce`` methods of
`~matplotlib.colorbar.Colorbar` are deprecated; both can be replaced by calls
to `~matplotlib.colorbar.Colorbar.update_normal`.

``OldScalarFormatter``, ``IndexFormatter`` and ``DateIndexFormatter``
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the deprecation for OldScalarFormatter. While you are at it, maybe also deprecate OldAutoLocator. I think the renaming of these things to "Old" was probably done with eventual deprecation and removal in mind. The IndexFormatters also seem like good candidates for the trash bin. I can imagine NullFormatter being useful in a user interface as one of a choice of Formatters, but it's true, it can be trivially recreated directly or via FuncFormatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, added it for OldScalarFormatter. Also deprecated OldAutoLocator.
NullFormatter is trivial to recreate with FuncFormatter (or even simpler, FormatStrFormatter("") :-)), but I think it's widely used enough and its implementation so simple that we can leave it in, at least for now.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These formatters are deprecated. Their functionality can be implemented using
e.g. `.FuncFormatter`.

``OldAutoLocator``
~~~~~~~~~~~~~~~~~~
This ticker is deprecated.
1 change: 1 addition & 0 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def set_tzinfo(self, tz):
self.tz = tz


@cbook.deprecated("3.3")
class IndexDateFormatter(ticker.Formatter):
"""Use with `.IndexLocator` to cycle format strings by index."""

Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest

import matplotlib
from matplotlib import cbook
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

Expand Down Expand Up @@ -457,7 +458,8 @@ class TestIndexFormatter:
(2, 'label2'),
(2.5, '')])
def test_formatting(self, x, label):
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
with cbook._suppress_matplotlib_deprecation_warning():
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
Copy link
Member

Choose a reason for hiding this comment

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

If we are deprecating, is there any reason to keep the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the usual policy is to get rid of the test only when the API is deprecated too.

Copy link
Member

Choose a reason for hiding this comment

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

I guess that makes sense because we can't break things until we can break them...

assert formatter(x) == label


Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def _set_locator(self, locator):
pass


@cbook.deprecated("3.3")
class IndexFormatter(Formatter):
"""
Format the position x to the nearest i-th label where ``i = int(x + 0.5)``.
Expand Down Expand Up @@ -322,13 +323,10 @@ def __call__(self, x, pos=None):


class NullFormatter(Formatter):
"""
Always return the empty string.
"""
"""Always return the empty string."""

def __call__(self, x, pos=None):
"""
Returns an empty string for all inputs.
"""
# docstring inherited
return ''


Expand Down Expand Up @@ -428,6 +426,7 @@ def __call__(self, x, pos=None):
return self.fmt.format(x=x, pos=pos)


@cbook.deprecated("3.3")
class OldScalarFormatter(Formatter):
"""
Tick location is a plain old number.
Expand Down Expand Up @@ -2867,6 +2866,7 @@ def tick_values(self, vmin, vmax):
'%s type.' % type(self))


@cbook.deprecated("3.3")
class OldAutoLocator(Locator):
"""
On autoscale this class picks the best MultipleLocator to set the
Expand Down