8000 Use atleast_3d instead of ensure_3d · matplotlib/matplotlib@2f5a633 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f5a633

Browse files
committed
Use atleast_3d instead of ensure_3d
It's not exactly the same, but we really use it just for empty arrays, so it shouldn't actually matter.
1 parent 3965858 commit 2f5a633

File tree

4 files changed

+3
-27
lines changed

4 files changed

+3
-27
lines changed

lib/matplotlib/cbook.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,21 +2244,6 @@ def _reshape_2D(X):
22442244
return X
22452245

22462246

2247-
def ensure_3d(arr):
2248-
"""
2249-
Return a version of arr with ndim==3, with extra dimensions added
2250-
at the end of arr.shape as needed.
2251-
"""
2252-
arr = np.asanyarray(arr)
2253-
if arr.ndim == 1:
2254-
arr = arr[:, None, None]
2255-
elif arr.ndim == 2:
2256-
arr = arr[:, :, None]
2257-
elif arr.ndim > 3 or arr.ndim < 1:
2258-
raise ValueError("cannot convert arr to 3-dimensional")
2259-
return arr
2260-
2261-
22622247
def violin_stats(X, method, points=100):
22632248
'''
22642249
Returns a list of dictionaries of data which can be used to draw a series

lib/matplotlib/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from numpy import ma
2525

2626
from matplotlib import _path
27-
from matplotlib.cbook import simple_linear_interpolation, maxdict, ensure_3d
27+
from matplotlib.cbook import simple_linear_interpolation, maxdict
2828
from matplotlib import rcParams
2929

3030

@@ -988,7 +988,7 @@ def get_path_collection_extents(
988988
if len(paths) == 0:
989989
raise ValueError("No paths provided")
990990
return Bbox.from_extents(*_path.get_path_collection_extents(
991-
master_transform, paths, ensure_3d(transforms),
991+
master_transform, paths, np.atleast_3d(transforms),
992992
offsets, offset_transform))
993993

994994

lib/matplotlib/tests/test_cbook.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,3 @@ def test_step_fails():
376376
np.arange(12))
377377
assert_raises(ValueError, cbook._step_validation,
378378
np.arange(12), np.arange(3))
379-
380-
381-
def test_ensure_3d():
382-
assert_array_equal([[[1]], [[2]], [[3]]],
383-
cbook.ensure_3d([1, 2, 3]))
384-
assert_array_equal([[[1], [2]], [[3], [4]]],
385-
cbook.ensure_3d([[1, 2], [3, 4]]))
386-
assert_raises(ValueError, cbook.ensure_3d, [[[[1]]]])

lib/matplotlib/transforms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from sets import Set as set
4949

5050
from .path import Path
51-
from .cbook import ensure_3d
5251

5352
DEBUG = False
5453
# we need this later, but this is very expensive to set up
@@ -668,7 +667,7 @@ def count_overlaps(self, bboxes):
668667
bboxes is a sequence of :class:`BboxBase` objects
669668
"""
670669
return count_bboxes_overlapping_bbox(
671-
self, ensure_3d([np.array(x) for x in bboxes]))
670+
self, np.atleast_3d([np.array(x) for x in bboxes]))
672671

673672
def expanded(self, sw, sh):
674673
"""

0 commit comments

Comments
 (0)
0