Skip to content

Commit 8e73998

Browse files
committed
Remove 3.8 cbook deprecations
1 parent 04365ba commit 8e73998

File tree

4 files changed

+23
-139
lines changed

4 files changed

+23
-139
lines changed

doc/api/next_api_changes/removals/28874-ES.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ which should cover most use cases.
6161
... with no replacement.
6262

6363

64+
``cbook`` API changes
65+
~~~~~~~~~~~~~~~~~~~~~
66+
67+
``cbook.Stack`` has been removed with no replacement.
68+
69+
``Grouper.clean()`` has been removed with no replacement. The Grouper class now cleans
70+
itself up automatically.
71+
72+
The *np_load* parameter of ``cbook.get_sample_data`` has been removed; `.get_sample_data`
73+
now auto-loads numpy arrays. Use ``get_sample_data(..., asfileobj=False)`` instead to get
74+
the filename of the data file, which can then be passed to `open`, if desired.
75+
76+
6477
``axes_grid1`` API changes
6578
~~~~~~~~~~~~~~~~~~~~~~~~~~
6679

lib/matplotlib/backend_tools.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class ToolXScale(AxisScaleBase):
7575
def set_scale(self, ax, scale: str | ScaleBase) -> None: ...
7676

7777
class ToolViewsPositions(ToolBase):
78-
views: dict[Figure | Axes, cbook.Stack]
79-
positions: dict[Figure | Axes, cbook.Stack]
78+
views: dict[Figure | Axes, cbook._Stack]
79+
positions: dict[Figure | Axes, cbook._Stack]
8080
home_views: dict[Figure, dict[Axes, tuple[float, float, float, float]]]
8181
def add_figure(self, figure: Figure) -> None: ...
8282
def clear(self, figure: Figure) -> None: ...

lib/matplotlib/cbook.py

Lines changed: 2 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,7 @@ def is_scalar_or_string(val):
543543
return isinstance(val, str) or not np.iterable(val)
544544

545545

546-
@_api.delete_parameter(
547-
"3.8", "np_load", alternative="open(get_sample_data(..., asfileobj=False))")
548-
def get_sample_data(fname, asfileobj=True, *, np_load=True):
546+
def get_sample_data(fname, asfileobj=True):
549547
"""
550548
Return a sample data file. *fname* is a path relative to the
551549
:file:`mpl-data/sample_data` directory. If *asfileobj* is `True`
@@ -564,10 +562,7 @@ def get_sample_data(fname, asfileobj=True, *, np_load=True):
564562
if suffix == '.gz':
565563
return gzip.open(path)
566564
elif suffix in ['.npy', '.npz']:
567-
if np_load:
568-
return np.load(path)
569-
else:
570-
return path.open('rb')
565+
return np.load(path)
571566
elif suffix in ['.csv', '.xrc', '.txt']:
572567
return path.open('r')
573568
else:
@@ -607,113 +602,6 @@ def flatten(seq, scalarp=is_scalar_or_string):
607602
yield from flatten(item, scalarp)
608603

609604

610-
@_api.deprecated("3.8")
611-
class Stack:
612-
"""
613-
Stack of elements with a movable cursor.
614-
615-
Mimics home/back/forward in a web browser.
616-
"""
617-
618-
def __init__(self, default=None):
619-
self.clear()
620-
self._default = default
621-
622-
def __call__(self):
623-
"""Return the current element, or None."""
624-
if not self._elements:
625-
return self._default
626-
else:
627-
return self._elements[self._pos]
628-
629-
def __len__(self):
630-
return len(self._elements)
631-
632-
def __getitem__(self, ind):
633-
return self._elements[ind]
634-
635-
def forward(self):
636-
"""Move the position forward and return the current element."""
637-
self._pos = min(self._pos + 1, len(self._elements) - 1)
638-
return self()
639-
640-
def back(self):
641-
"""Move the position back and return the current element."""
642-
if self._pos > 0:
643-
self._pos -= 1
644-
return self()
645-
646-
def push(self, o):
647-
"""
648-
Push *o* to the stack at current position. Discard all later elements.
649-
650-
*o* is returned.
651-
"""
652-
self._elements = self._elements[:self._pos + 1] + [o]
653-
self._pos = len(self._elements) - 1
654-
return self()
655-
656-
def home(self):
657-
"""
658-
Push the first element onto the top of the stack.
659-
660-
The first element is returned.
661-
"""
662-
if not self._elements:
663-
return
664-
self.push(self._elements[0])
665-
return self()
666-
667-
def empty(self):
668-
"""Return whether the stack is empty."""
669-
return len(self._elements) == 0
670-
671-
def clear(self):
672-
"""Empty the stack."""
673-
self._pos = -1
674-
self._elements = []
675-
676-
def bubble(self, o):
677-
"""
678-
Raise all references of *o* to the top of the stack, and return it.
679-
680-
Raises
681-
------
682-
ValueError
683-
If *o* is not in the stack.
684-
"""
685-
if o not in self._elements:
686-
raise ValueError('Given element not contained in the stack')
687-
old_elements = self._elements.copy()
688-
self.clear()
689-
top_elements = []
690-
for elem in old_elements:
691-
if elem == o:
692-
top_elements.append(elem)
693-
else:
694-
self.push(elem)
695-
for _ in top_elements:
696-
self.push(o)
697-
return o
698-
699-
def remove(self, o):
700-
"""
701-
Remove *o* from the stack.
702-
703-
Raises
704-
------
705-
ValueError
706-
If *o* is not in the stack.
707-
"""
708-
if o not in self._elements:
709-
raise ValueError('Given element not contained in the stack')
710-
old_elements = self._elements.copy()
711-
self.clear()
712-
for elem in old_elements:
713-
if elem != o:
714-
self.push(elem)
715-
716-
717605
class _Stack:
718606
"""
719607
Stack of elements with a movable cursor.
@@ -913,10 +801,6 @@ def __setstate__(self, state):
913801
def __contains__(self, item):
914802
return item in self._mapping
915803

916-
@_api.deprecated("3.8", alternative="none, you no longer need to clean a Grouper")
917-
def clean(self):
918-
"""Clean dead weak references from the dictionary."""
919-
920804
def join(self, a, *args):
921805
"""
922806
Join given arguments into the same set. Accepts one or more arguments.

lib/matplotlib/cbook.pyi

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,25 @@ def open_file_cm(
7474
def is_scalar_or_string(val: Any) -> bool: ...
7575
@overload
7676
def get_sample_data(
77-
fname: str | os.PathLike, asfileobj: Literal[True] = ..., *, np_load: Literal[True]
78-
) -> np.ndarray: ...
77+
fname: str | os.PathLike, asfileobj: Literal[True] = ...
78+
) -> np.ndarray | IO: ...
7979
@overload
80-
def get_sample_data(
81-
fname: str | os.PathLike,
82-
asfileobj: Literal[True] = ...,
83-
*,
84-
np_load: Literal[False] = ...,
85-
) -> IO: ...
86-
@overload
87-
def get_sample_data(
88-
fname: str | os.PathLike, asfileobj: Literal[False], *, np_load: bool = ...
89-
) -> str: ...
80+
def get_sample_data(fname: str | os.PathLike, asfileobj: Literal[False]) -> str: ...
9081
def _get_data_path(*args: Path | str) -> Path: ...
9182
def flatten(
9283
seq: Iterable[Any], scalarp: Callable[[Any], bool] = ...
9384
) -> Generator[Any, None, None]: ...
9485

95-
class Stack(Generic[_T]):
96-
def __init__(self, default: _T | None = ...) -> None: ...
86+
class _Stack(Generic[_T]):
87+
def __init__(self) -> None: ...
88+
def clear(self) -> None: ...
9789
def __call__(self) -> _T: ...
9890
def __len__(self) -> int: ...
9991
def __getitem__(self, ind: int) -> _T: ...
10092
def forward(self) -> _T: ...
10193
def back(self) -> _T: ...
10294
def push(self, o: _T) -> _T: ...
10395
def home(self) -> _T: ...
104-
def empty(self) -> bool: ...
105-
def clear(self) -> None: ...
106-
def bubble(self, o: _T) -> _T: ...
107-
def remove(self, o: _T) -> None: ...
10896

10997
def safe_masked_invalid(x: ArrayLike, copy: bool = ...) -> np.ndarray: ...
11098
def print_cycles(
@@ -114,7 +102,6 @@ def print_cycles(
114102
class Grouper(Generic[_T]):
115103
def __init__(self, init: Iterable[_T] = ...) -> None: ...
116104
def __contains__(self, item: _T) -> bool: ...
117-
def clean(self) -> None: ...
118105
def join(self, a: _T, *args: _T) -> None: ...
119106
def joined(self, a: _T, b: _T) -> bool: ...
120107
def remove(self, a: _T) -> None: ...

0 commit comments

Comments
 (0)