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

Skip to content

Commit 30ef0b5

Browse files
committed
Replace safezip() by more informative error message in errorbar().
Currently, the error for mismatched shapes in errorbar is ``` ValueError: In safezip, len(args[0])=2 but len(args[1])=3 ``` Replace it by ``` ValueError: The lengths of the data (2) and the error (3) do not match ``` and deprecate the not-so-informatively-named safezip.
1 parent 2fe337c commit 30ef0b5

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``cbook.safezip`` is deprecated (manually check the lengths of the inputs
5+
instead, or rely on numpy to do it).

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,8 +3200,13 @@ def extract_err(err, data):
32003200
raise ValueError(
32013201
"err must be a scalar or a 1D or (2, n) array-like")
32023202
# Using list comprehensions rather than arrays to preserve units.
3203-
low = [v - e for v, e in cbook.safezip(data, a)]
3204-
high = [v + e for v, e in cbook.safezip(data, b)]
3203+
for e in [a, b]:
3204+
if len(data) != len(e):
3205+
raise ValueError(
3206+
f"The lengths of the data ({len(data)}) and the "
3207+
f"error {len(e)} do not match")
3208+
low = [v - e for v, e in zip(data, a)]
3209+
high = [v + e for v, e in zip(data, b)]
32053210
return low, high
32063211

32073212
if xerr is not None:

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ def call(command, os_name):
776776
_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
777777

778778

779+
@deprecated("3.1")
779780
def safezip(*args):
780781
"""make sure *args* are equal len before zipping"""
781782
Nx = len(args[0])

0 commit comments

Comments
 (0)