Skip to content

Commit 7c012de

Browse files
authored
Increase coverage to 85% with targeted tests (#636)
1 parent bca0789 commit 7c012de

15 files changed

+2308
-16
lines changed

ultraplot/colors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,8 +2934,14 @@ def _translate_cmap(cmap, lut=None, cyclic=None, listedthresh=None):
29342934
# WARNING: Apply default 'cyclic' property to native matplotlib colormaps
29352935
# based on known names. Maybe slightly dangerous but cleanest approach
29362936
lut = _not_none(lut, rc["image.lut"])
2937-
cyclic = _not_none(cyclic, cmap.name and cmap.name.lower() in CMAPS_CYCLIC)
2937+
name = getattr(cmap, "name", None)
2938+
cyclic = _not_none(cyclic, name and name.lower() in CMAPS_CYCLIC)
29382939
listedthresh = _not_none(listedthresh, rc["cmap.listedthresh"])
2940+
if not isinstance(cmap, mcolors.Colormap):
2941+
raise ValueError(
2942+
f"Invalid colormap type {type(cmap).__name__!r}. "
2943+
"Must be instance of matplotlib.colors.Colormap."
2944+
)
29392945

29402946
# Translate the colormap
29412947
# WARNING: Here we ignore 'N' in order to respect ultraplotrc lut sizes
@@ -2957,12 +2963,6 @@ def _translate_cmap(cmap, lut=None, cyclic=None, listedthresh=None):
29572963
cmap = DiscreteColormap(colors, name)
29582964
elif isinstance(cmap, mcolors.Colormap): # base class
29592965
pass
2960-
else:
2961-
raise ValueError(
2962-
f"Invalid colormap type {type(cmap).__name__!r}. "
2963-
"Must be instance of matplotlib.colors.Colormap."
2964-
)
2965-
29662966
# Apply hidden settings
29672967
cmap._rgba_bad = bad
29682968
cmap._rgba_under = under

ultraplot/internals/rcsetup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _validate_color(value, alternative=None):
356356
def _validate_bool_or_iterable(value):
357357
if isinstance(value, bool):
358358
return _validate_bool(value)
359-
elif np.isiterable(value):
359+
elif np.iterable(value):
360360
return value
361361
raise ValueError(f"{value!r} is not a valid bool or iterable of node labels.")
362362

@@ -460,15 +460,15 @@ def _validate_float_or_iterable(value):
460460
try:
461461
return _validate_float(value)
462462
except Exception:
463-
if np.isiterable(value) and not isinstance(value, (str, bytes)):
463+
if np.iterable(value) and not isinstance(value, (str, bytes)):
464464
return tuple(_validate_float(item) for item in value)
465465
raise ValueError(f"{value!r} is not a valid float or iterable of floats.")
466466

467467

468468
def _validate_string_or_iterable(value):
469469
if isinstance(value, str):
470470
return _validate_string(value)
471-
if np.isiterable(value) and not isinstance(value, (str, bytes)):
471+
if np.iterable(value) and not isinstance(value, (str, bytes)):
472472
values = tuple(value)
473473
if all(isinstance(item, str) for item in values):
474474
return values
@@ -601,6 +601,8 @@ def _yaml_table(rcdict, comment=True, description=False):
601601

602602
# Generate string
603603
string = ""
604+
if not data:
605+
return string
604606
keylen = len(max(rcdict, key=len))
605607
vallen = len(max((tup[1] for tup in data), key=len))
606608
for key, value, descrip in data:

ultraplot/proj.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
f"The {self.name!r} projection does not handle elliptical globes."
8282
)
8383

84-
proj4_params = {"proj": "aitoff", "lon_0": central_longitude}
84+
proj4_params = [("proj", "aitoff"), ("lon_0", central_longitude)]
8585
super().__init__(
8686
proj4_params,
8787
central_longitude,
@@ -126,7 +126,7 @@ def __init__(
126126
f"The {self.name!r} projection does not handle elliptical globes."
127127
)
128128

129-
proj4_params = {"proj": "hammer", "lon_0": central_longitude}
129+
proj4_params = [("proj", "hammer"), ("lon_0", central_longitude)]
130130
super().__init__(
131131
proj4_params,
132132
central_longitude,
@@ -172,7 +172,7 @@ def __init__(
172172
f"The {self.name!r} projection does not handle elliptical globes."
173173
)
174174

175-
proj4_params = {"proj": "kav7", "lon_0": central_longitude}
175+
proj4_params = [("proj", "kav7"), ("lon_0", central_longitude)]
176176
super().__init__(
177177
proj4_params,
178178
central_longitude,
@@ -218,7 +218,7 @@ def __init__(
218218
f"The {self.name!r} projection does not handle " "elliptical globes."
219219
)
220220

221-
proj4_params = {"proj": "wintri", "lon_0": central_longitude}
221+
proj4_params = [("proj", "wintri"), ("lon_0", central_longitude)]
222222
super().__init__(
223223
proj4_params,
224224
central_longitude,

ultraplot/scale.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def inverted(self):
686686

687687
def transform_non_affine(self, a):
688688
with np.errstate(divide="ignore", invalid="ignore"):
689-
return np.rad2deg(np.arctan2(1, np.sinh(a)))
689+
return np.rad2deg(np.arctan(np.sinh(a)))
690690

691691

692692
class SineLatitudeScale(_Scale, mscale.ScaleBase):
@@ -853,7 +853,8 @@ def __init__(self, threshs, scales, zero_dists=None):
853853
with np.errstate(divide="ignore", invalid="ignore"):
854854
dists = np.concatenate((threshs[:1], dists / scales[:-1]))
855855
if zero_dists is not None:
856-
dists[scales[:-1] == 0] = zero_dists
856+
zero_idx = np.flatnonzero(scales[:-1] == 0) + 1
857+
dists[zero_idx] = zero_dists
857858
self._dists = dists
858859

859860
def inverted(self):

0 commit comments

Comments
 (0)