8000 Deprecate old and little used formatters. · matplotlib/matplotlib@52d08fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 52d08fc

Browse files
committed
Deprecate old and little used formatters.
- The new ScalarFormatter replaced OldScalarFormatter in 3910bb9 (2005). - IndexFormatter appeared in e66091d (2009) but was never used in the examples; IndexDateFormatter is unused in the docs since 4ea4b96 (2009); both can be fairly easily implemented in terms of FuncFormatter. I'm willing to back off the deprecations if there's demand to keep them, though.
1 parent 860803d commit 52d08fc

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,8 @@ access the transform classes from the :mod:`.scale` module.
135135
``TexManager.cachedir``
136136
~~~~~~~~~~~~~~~~~~~~~~~
137137
Use `matplotlib.get_cachedir()` instead.
138+
139+
``OldScalarFormatter``, ``IndexFormatter`` and ``DateIndexFormatter``
140+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141+
These formatters are deprecated. Their functionality can be implemented using
142+
e.g. `.FuncFormatter`.

lib/matplotlib/dates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ def set_tzinfo(self, tz):
604604
self.tz = tz
605605

606606

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

lib/matplotlib/tests/test_ticker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import matplotlib
13+
from matplotlib import cbook
1314
import matplotlib.pyplot as plt
1415
import matplotlib.ticker as mticker
1516

@@ -457,7 +458,8 @@ class TestIndexFormatter:
457458
(2, 'label2'),
458459
(2.5, '')])
459460
def test_formatting(self, x, label):
460-
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
461+
with cbook._suppress_matplotlib_deprecation_warning():
462+
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
461463
assert formatter(x) == label
462464

463465

lib/matplotlib/ticker.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def _set_locator(self, locator):
293293
pass
294294

295295

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

323324

324325
class NullFormatter(Formatter):
325-
"""
326-
Always return the empty string.
327-
"""
326+
"""Always return the empty string."""
327+
328328
def __call__(self, x, pos=None):
329-
"""
330-
Returns an empty string for all inputs.
331-
"""
329+
# docstring inherited
332330
return ''
333331

334332

0 commit comments

Comments
 (0)
0