Skip to content

Commit d6ab941

Browse files
committed
Fix numpy >= 1.20 deprecation warnings
1 parent 294c9ee commit d6ab941

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

proplot/axes/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ def _parse_markersize(
30683068
else:
30693069
s = s.copy()
30703070
s.flat[:] = utils.units(s.flat, 'pt')
3071-
s = s.astype(np.float) ** 2
3071+
s = s.astype(np.float64) ** 2
30723072
if absolute_size is None:
30733073
if _inside_seaborn_call():
30743074
absolute_size = True

proplot/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def save(self, path=None, alpha=True):
12411241
--------
12421242
DiscreteColormap.save
12431243
"""
1244-
# NOTE We sanitize segmentdata before saving to json. Convert np.float to
1244+
# NOTE: We sanitize segmentdata before saving to json. Convert numpy float to
12451245
# builtin float, np.array to list of lists, and callable to list of lists.
12461246
# We tried encoding func.__code__ with base64 and marshal instead, but when
12471247
# cmap.append() embeds functions as keyword arguments, this seems to make it

proplot/figure.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,12 @@ def _add_subplots(
10751075
# TODO: Consider deprecating and asking users to use add_subplot()
10761076
def _axes_dict(naxs, input, kw=False, default=None):
10771077
# First build up dictionary
1078-
# 1. 'string' or {1: 'string1', (2, 3): 'string2'}
1079-
if not kw:
1078+
if not kw: # 'string' or {1: 'string1', (2, 3): 'string2'}
10801079
if np.iterable(input) and not isinstance(input, (str, dict)):
10811080
input = {num + 1: item for num, item in enumerate(input)}
10821081
elif not isinstance(input, dict):
10831082
input = {range(1, naxs + 1): input}
1084-
# 2. {'prop': value} or {1: {'prop': value1}, (2, 3): {'prop': value2}}
1085-
else:
1083+
else: # {key: value} or {1: {key: value1}, (2, 3): {key: value2}}
10861084
nested = [isinstance(_, dict) for _ in input.values()]
10871085
if not any(nested): # any([]) == False
10881086
input = {range(1, naxs + 1): input.copy()}
@@ -1118,7 +1116,7 @@ def _axes_dict(naxs, input, kw=False, default=None):
11181116
else:
11191117
array = np.atleast_1d(array)
11201118
array[array == None] = 0 # None or 0 both valid placeholders # noqa: E711
1121-
array = array.astype(np.int)
1119+
array = array.astype(int)
11221120
if array.ndim == 1: # interpret as single row or column
11231121
array = array[None, :] if order == 'C' else array[:, None]
11241122
elif array.ndim != 2:

proplot/internals/inputs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _is_numeric(data):
7171
array = _to_numpy_array(data)
7272
return len(data) and (
7373
np.issubdtype(array.dtype, np.number)
74-
or np.issubdtype(array.dtype, np.object)
74+
or np.issubdtype(array.dtype, object)
7575
and all(isinstance(_, np.number) for _ in array.flat)
7676
)
7777

@@ -82,9 +82,9 @@ def _is_categorical(data):
8282
"""
8383
array = _to_numpy_array(data)
8484
return len(data) and (
85-
np.issubdtype(array.dtype, np.str)
86-
or np.issubdtype(array.dtype, np.object)
87-
and any(isinstance(_, np.str) for _ in array.flat)
85+
np.issubdtype(array.dtype, str)
86+
or np.issubdtype(array.dtype, object)
87+
and any(isinstance(_, str) for _ in array.flat)
8888
)
8989

9090

@@ -161,7 +161,7 @@ def _to_masked_array(data, *, copy=False):
161161
else:
162162
data = ma.masked_invalid(data, copy=copy)
163163
if np.issubdtype(data.dtype, np.integer):
164-
data = data.astype(np.float)
164+
data = data.astype(np.float64)
165165
if np.issubdtype(data.dtype, np.number):
166166
data.fill_value *= np.nan # default float fill_value is 1e+20 or 1e+20 + 0j
167167
else:
@@ -508,7 +508,7 @@ def _safe_range(data, lo=0, hi=100):
508508
if data.size:
509509
min_ = np.min(data) if lo <= 0 else np.percentile(data, lo)
510510
if hasattr(min_, 'dtype') and np.issubdtype(min_.dtype, np.integer):
511-
min_ = np.float(min_)
511+
min_ = np.float64(min_)
512512
try:
513513
is_finite = np.isfinite(min_)
514514
except TypeError:
@@ -520,7 +520,7 @@ def _safe_range(data, lo=0, hi=100):
520520
if data.size:
521521
max_ = np.max(data) if hi >= 100 else np.percentile(data, hi)
522522
if hasattr(max_, 'dtype') and np.issubdtype(max_.dtype, np.integer):
523-
max_ = np.float(max_)
523+
max_ = np.float64(max_)
524524
try:
525525
is_finite = np.isfinite(min_)
526526
except TypeError:

proplot/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def set_params(self, steps=None, nbins=None, minor=None, min_n_ticks=None):
183183
Set the parameters for this locator. See `DiscreteLocator` for details.
184184
"""
185185
if steps is not None:
186-
steps = np.unique(np.asarray(steps, dtype=np.int)) # also sorts, makes 1D
186+
steps = np.unique(np.asarray(steps, dtype=int)) # also sorts, makes 1D
187187
if np.any(steps < 1) or np.any(steps > 10):
188188
raise ValueError('Steps must fall between one and ten (inclusive).')
189189
if steps[0] != 1:

0 commit comments

Comments
 (0)