Skip to content

Commit e4c6d63

Browse files
committed
MNT: Privatize Formatter attributes
1 parent 49fd492 commit e4c6d63

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

lib/matplotlib/dates.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ class ConciseDateFormatter(ticker.Formatter):
665665
666666
"""
667667

668+
offset_string = _api.deprecate_privatize_attribute(
669+
"3.11", alternative="get_offset()"
670+
)
671+
668672
def __init__(self, locator, tz=None, formats=None, offset_formats=None,
669673
zero_formats=None, show_offset=True, *, usetex=None):
670674
"""
@@ -719,7 +723,7 @@ def __init__(self, locator, tz=None, formats=None, offset_formats=None,
719723
'%Y-%b-%d',
720724
'%Y-%b-%d',
721725
'%Y-%b-%d %H:%M']
722-
self.offset_string = ''
726+
self._offset_string = ''
723727
self.show_offset = show_offset
724728
self._usetex = mpl._val_or_rc(usetex, 'text.usetex')
725729

lib/matplotlib/testing/jpl_units/UnitDblFormatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UnitDblFormatter(ticker.ScalarFormatter):
1414

1515
def __call__(self, x, pos=None):
1616
# docstring inherited
17-
if len(self.locs) == 0:
17+
if len(self._locs) == 0:
1818
return ''
1919
else:
2020
return f'{x:.12}'

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):
920920
ax.yaxis.set_major_locator(mticker.MaxNLocator(4))
921921

922922
tmp_form.set_locs(ax.yaxis.get_majorticklocs())
923-
assert orderOfMag == tmp_form.orderOfMagnitude
923+
assert orderOfMag == tmp_form._orderOfMagnitude
924924

925925
@pytest.mark.parametrize('value, expected', format_data)
926926
def test_format_data(self, value, expected):

lib/matplotlib/ticker.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ class Formatter(TickHelper):
202202
"""
203203
# some classes want to see all the locs to help format
204204
# individual ones
205-
locs = []
205+
_locs = []
206+
207+
locs = _api.deprecate_privatize_attribute("3.11")
206208

207209
def __call__(self, x, pos=None):
208210
"""
@@ -250,7 +252,7 @@ def set_locs(self, locs):
250252
This method is called before computing the tick labels because some
251253
formatters need to know all tick locations to do so.
252254
"""
253-
self.locs = locs
255+
self._locs = locs
254256

255257
@staticmethod
256258
def fix_minus(s):
@@ -458,15 +460,18 @@ class ScalarFormatter(Formatter):
458460
459461
"""
460462

463+
orderOfMagniture = _api.deprecate_privatize_attribute("3.11")
464+
format = _api.deprecate_privatize_attribute("3.11")
465+
461466
def __init__(self, useOffset=None, useMathText=None, useLocale=None, *,
462467
usetex=None):
463468
useOffset = mpl._val_or_rc(useOffset, 'axes.formatter.useoffset')
464469
self._offset_threshold = mpl.rcParams['axes.formatter.offset_threshold']
465470
self.set_useOffset(useOffset)
466471
self.set_usetex(usetex)
467472
self.set_useMathText(useMathText)
468-
self.orderOfMagnitude = 0
469-
self.format = ''
473+
self._orderOfMagnitude = 0
474+
self._format = ''
470475
self._scientific = True
471476
self._powerlimits = mpl.rcParams['axes.formatter.limits']
472477
self.set_useLocale(useLocale)
@@ -1446,7 +1451,7 @@ def __call__(self, x, pos=None):
14461451
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
14471452
if abs(xp) < 1e-8:
14481453
xp = 0
1449-
return self._format_maybe_minus_and_locale(self.format, xp)
1454+
return self._format_maybe_minus_and_locale(self._format, xp)
14501455

14511456
def set_locs(self, locs):
14521457
# docstring inherited

lib/matplotlib/ticker.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TickHelper:
2323
def create_dummy_axis(self, **kwargs) -> None: ...
2424

2525
class Formatter(TickHelper):
26-
locs: list[float]
26+
_locs: list[float]
2727
def __call__(self, x: float, pos: int | None = ...) -> str: ...
2828
def format_ticks(self, values: list[float]) -> list[str]: ...
2929
def format_data(self, value: float) -> str: ...
@@ -57,8 +57,8 @@ class StrMethodFormatter(Formatter):
5757
def __init__(self, fmt: str) -> None: ...
5858

5959
class ScalarFormatter(Formatter):
60-
orderOfMagnitude: int
61-
format: str
60+
_orderOfMagnitude: int
61+
_format: str
6262
def __init__(
6363
self,
6464
useOffset: bool | float | None = ...,

0 commit comments

Comments
 (0)