Skip to content

Commit a7954cf

Browse files
authored
Merge pull request #101 from ocefpaf/numpy20
Fix for numpy 2.0...
2 parents 86ffec5 + 10772d8 commit a7954cf

File tree

12 files changed

+81
-78
lines changed

12 files changed

+81
-78
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
strategy:
1212
matrix:
13-
python-version: ["3.10", "3.11", "3.12"]
13+
python-version: [ "3.10", "3.11", "3.12" ]
1414
os: [ubuntu-latest]
1515
fail-fast: false
1616

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ repos:
2828
- id: blackdoc
2929

3030
- repo: https://github.com/charliermarsh/ruff-pre-commit
31-
rev: v0.3.5
31+
rev: v0.5.5
3232
hooks:
3333
- id: ruff
3434

3535
- repo: https://github.com/psf/black
36-
rev: 24.3.0
36+
rev: 24.4.2
3737
hooks:
3838
- id: black
3939
language_version: python3
4040

4141
- repo: https://github.com/codespell-project/codespell
42-
rev: v2.2.6
42+
rev: v2.3.0
4343
hooks:
4444
- id: codespell
4545
args:
@@ -51,6 +51,6 @@ repos:
5151
- id: add-trailing-comma
5252

5353
- repo: https://github.com/tox-dev/pyproject-fmt
54-
rev: "1.7.0"
54+
rev: "2.2.0"
5555
hooks:
5656
- id: pyproject-fmt

oceans/RPSstuff.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def h2hms(hours):
1313
Examples
1414
--------
1515
>>> h2hms(12.51)
16-
(12.0, 30.0, 36.0)
16+
(np.float64(12.0), np.float64(30.0), np.float64(36.0))
1717
1818
"""
1919
hour = np.floor(hours)
@@ -33,7 +33,7 @@ def hms2h(h, m=None, s=None):
3333
12.51
3434
>>> # Or,
3535
>>> hms2h(123036)
36-
12.51
36+
np.float64(12.51)
3737
3838
"""
3939
if not m and not s:
@@ -55,7 +55,7 @@ def ms2hms(millisecs):
5555
Examples
5656
--------
5757
>>> ms2hms(1e3 * 60)
58-
(0.0, 1.0, 0.0)
58+
(np.float64(0.0), np.float64(1.0), np.float64(0.0))
5959
6060
"""
6161
sec = np.round(millisecs / 1000)
@@ -233,7 +233,7 @@ def s2hms(secs):
233233
Examples
234234
--------
235235
>>> s2hms(3600 + 60 + 1)
236-
(1.0, 1.0, 1)
236+
(np.float64(1.0), np.float64(1.0), np.int64(1))
237237
238238
"""
239239
hr = np.floor(secs / 3600)
@@ -509,7 +509,7 @@ def fixcoast(coast):
509509
"""
510510

511511
ind = coast == -99999.0
512-
coast[ind] = np.NaN
512+
coast[ind] = np.nan
513513

514514
ind = np.where(np.isnan(coast[:, 0]))[0]
515515
dind = np.diff(ind)
@@ -518,9 +518,9 @@ def fixcoast(coast):
518518
coast = np.delete(coast, ind[idup], axis=0)
519519

520520
if not np.isnan(coast[0, 0]):
521-
coast = np.insert(coast, 0, np.NaN, axis=0)
521+
coast = np.insert(coast, 0, np.nan, axis=0)
522522

523523
if not np.isnan(coast[-1, -1]):
524-
coast = np.append(coast, np.c_[np.NaN, np.NaN], axis=0)
524+
coast = np.append(coast, np.c_[np.nan, np.nan], axis=0)
525525

526526
return coast

oceans/colormaps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ def load_cmap(fname):
142142
}
143143

144144
# Data colormaps.
145-
for fname in glob("%s/*.dat" % cmap_path):
145+
for fname in glob(f"{cmap_path}/*.dat"):
146146
cmap = os.path.basename(fname).split(".")[0]
147147
data = load_cmap(fname)
148148
arrays.update({cmap: data})
149149

150150
cm = Bunch()
151151
for key, value in arrays.items():
152152
cm.update({key: cmat2cmpl(value)})
153-
cm.update({"%s_r" % key: cmat2cmpl(value, reverse=True)})
153+
cm.update({f"{key}_r": cmat2cmpl(value, reverse=True)})
154154

155155

156156
def demo():

oceans/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _woa_variable(variable):
2828

2929

3030
def _woa_url(variable, time_period, resolution):
31-
base = "https://data.nodc.noaa.gov/thredds/dodsC"
31+
base = "https://www.ncei.noaa.gov/thredds-ocean/dodsC"
3232

3333
v = _woa_variable(variable)
3434

oceans/filters.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14):
178178
# Checking window type and dimensions
179179
kinds = ["hann", "hamming", "blackman", "bartlett", "kaiser"]
180180
if kind not in kinds:
181-
raise ValueError("Invalid window type requested: %s" % kind)
181+
raise ValueError(f"Invalid window type requested: {kind}")
182182

183183
if (np.mod(hei, 2) == 0) or (np.mod(wid, 2) == 0):
184184
raise ValueError("Window dimensions must be odd")
@@ -205,7 +205,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14):
205205
A = np.asanyarray(A)
206206
Fnan = np.isnan(A)
207207
imax, jmax = A.shape
208-
As = np.NaN * np.ones((imax, jmax))
208+
As = np.nan * np.ones((imax, jmax))
209209

210210
for i in range(imax):
211211
for j in range(jmax):
@@ -257,7 +257,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14):
257257
a = Ac * wdwc
258258
As[i, j] = a.sum() / wdwc.sum()
259259
# Assigning NaN to the positions holding NaNs in the original array.
260-
As[Fnan] = np.NaN
260+
As[Fnan] = np.nan
261261

262262
return As
263263

@@ -302,7 +302,7 @@ def weim(x, N, kind="hann", badflag=-9999, beta=14):
302302
# Checking window type and dimensions.
303303
kinds = ["hann", "hamming", "blackman", "bartlett", "kaiser"]
304304
if kind not in kinds:
305-
raise ValueError("Invalid window type requested: %s" % kind)
305+
raise ValueError(f"Invalid window type requested: {kind}")
306306

307307
if np.mod(N, 2) == 0:
308308
raise ValueError("Window size must be odd")
@@ -329,7 +329,7 @@ def weim(x, N, kind="hann", badflag=-9999, beta=14):
329329
ln = (N - 1) / 2
330330
lx = x.size
331331
lf = lx - ln
332-
xs = np.NaN * np.ones(lx)
332+
xs = np.nan * np.ones(lx)
333333

334334
# Eliminating bad data from mean computation.
335335
fbad = x == badflag
@@ -459,7 +459,7 @@ def medfilt1(x, L=3):
459459
msg = "Input sequence has to be 1d: ndim = {}".format
460460
raise ValueError(msg(xin.ndim))
461461

462-
xout = np.zeros_like(xin) + np.NaN
462+
xout = np.zeros_like(xin) + np.nan
463463

464464
Lwing = (L - 1) // 2
465465

@@ -538,7 +538,7 @@ def md_trenberth(x):
538538
>>> filtered = md_trenberth(x)
539539
>>> fig, ax = plt.subplots()
540540
>>> (l1,) = ax.plot(t, x, label="original")
541-
>>> pad = [np.NaN] * 5
541+
>>> pad = [np.nan] * 5
542542
>>> (l2,) = ax.plot(t, np.r_[pad, filtered, pad], label="filtered")
543543
>>> legend = ax.legend()
544544
@@ -598,9 +598,9 @@ def pl33tn(x, dt=1.0, T=33.0, mode="valid", t=None):
598598
>>> filtered_33d3 = pl33tn(x, dt=4.0, T=72.0) # 3 day filter
599599
>>> fig, ax = plt.subplots()
600600
>>> (l1,) = ax.plot(t, x, label="original")
601-
>>> pad = [np.NaN] * 8
601+
>>> pad = [np.nan] * 8
602602
>>> (l2,) = ax.plot(t, np.r_[pad, filtered_33, pad], label="33 hours")
603-
>>> pad = [np.NaN] * 17
603+
>>> pad = [np.nan] * 17
604604
>>> (l3,) = ax.plot(t, np.r_[pad, filtered_33d3, pad], label="3 days")
605605
>>> legend = ax.legend()
606606

oceans/ocfis.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gsw
55
import numpy as np
66
import numpy.ma as ma
7+
import pandas as pd
78

89

910
def spdir2uv(spd, ang, deg=False):
@@ -583,7 +584,7 @@ def bin_dates(self, freq, tz=None):
583584
>>> from pandas import Series, date_range
584585
>>> n = 24 * 30
585586
>>> sig = np.random.rand(n) + 2 * np.cos(2 * np.pi * np.arange(n))
586-
>>> dates = date_range(start="1/1/2000", periods=n, freq="H")
587+
>>> dates = date_range(start="1/1/2000", periods=n, freq="h")
587588
>>> series = Series(data=sig, index=dates)
588589
>>> new_series = bin_dates(series, freq="D", tz=None)
589590
@@ -593,7 +594,7 @@ def bin_dates(self, freq, tz=None):
593594
new_index = date_range(start=self.index[0], end=self.index[-1], freq=freq, tz=tz)
594595
new_series = self.groupby(new_index.asof).mean()
595596
# Averages at the center.
596-
secs = new_index.freq.delta.total_seconds()
597+
secs = pd.Timedelta(new_index.freq).total_seconds()
597598
new_series.index = new_series.index.values + int(secs // 2)
598599
return new_series
599600

@@ -625,7 +626,7 @@ def series_spline(self):
625626

626627
def despike(self, n=3, recursive=False):
627628
"""
628-
Replace spikes with np.NaN.
629+
Replace spikes with np.nan.
629630
Removing spikes that are >= n * std.
630631
default n = 3.
631632
@@ -638,12 +639,12 @@ def despike(self, n=3, recursive=False):
638639
)
639640

640641
removed = np.count_nonzero(outliers)
641-
result[outliers] = np.NaN
642+
result[outliers] = np.nan
642643

643644
counter = 0
644645
if recursive:
645646
while outliers.any():
646-
result[outliers] = np.NaN
647+
result[outliers] = np.nan
647648
base = np.abs(result - np.nanmean(result))
648649
outliers = base >= n * np.nanstd(result)
649650
counter += 1
@@ -658,7 +659,7 @@ def pol2cart(theta, radius, units="deg"):
658659
Examples
659660
--------
660661
>>> pol2cart(0, 1, units="deg")
661-
(1.0, 0.0)
662+
(np.float64(1.0), np.float64(0.0))
662663
663664
"""
664665
if units in ["deg", "degs"]:
@@ -781,7 +782,7 @@ def get_profile(x, y, f, xi, yi, mode="nearest", order=3):
781782
return map_coordinates(f, coords, mode=mode, order=order)
782783

783784

784-
def strip_mask(arr, fill_value=np.NaN):
785+
def strip_mask(arr, fill_value=np.nan):
785786
"""
786787
Take a masked array and return its data(filled) + mask.
787788

oceans/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def level_colormap(levels, cmap=None):
130130
cdict = {"red": tuple(R), "green": tuple(G), "blue": tuple(B)}
131131

132132
return matplotlib.colors.LinearSegmentedColormap(
133-
"%s_levels" % cmap.name,
133+
f"{cmap.name}_levels",
134134
cdict,
135135
256,
136136
)

oceans/sw_extras/gamma_GP_from_SP_pt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def gamma_GP_from_SP_pt(SP, pt, p, lon, lat):
445445
gamma_Pac = gamma_G_pacific(SP, pt)
446446
gamma_Ind = gamma_G_indian(SP, pt)
447447
gamma_SOce = gamma_G_southern_ocean(SP, pt, p)
448-
# gamma_Arc = np.zeros_like(SP) * np.NaN
448+
# gamma_Arc = np.zeros_like(SP) * np.nan
449449

450450
# Definition of the Indian part.
451451
io_lon = np.array(
@@ -590,7 +590,7 @@ def gamma_GP_from_SP_pt(SP, pt, p, lon, lat):
590590
gamma_GP = w_so * gamma_SOce + (1.0 - w_so) * gamma_middle
591591

592592
# Set NaN in the arctic region.
593-
gamma_GP[lat > 66.0] = np.NaN
593+
gamma_GP[lat > 66.0] = np.nan
594594

595595
# De-normalization.
596596
gamma_GP = 20.0 * gamma_GP - 20

oceans/sw_extras/sw_extras.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def cor_beta(lat):
321321
--------
322322
>>> import oceans.sw_extras.sw_extras as swe
323323
>>> swe.cor_beta(0)
324-
2.2891225867210798e-11
324+
np.float64(2.2891225867210798e-11)
325325
326326
References
327327
----------
@@ -358,7 +358,7 @@ def inertial_period(lat):
358358
>>> import oceans.sw_extras.sw_extras as swe
359359
>>> lat = 30.0
360360
>>> swe.inertial_period(lat) / 3600
361-
23.93484986278565
361+
np.float64(23.93484986278565)
362362
363363
"""
364364
lat = np.asanyarray(lat)
@@ -427,7 +427,7 @@ def visc(s, t, p):
427427
--------
428428
>>> import oceans.sw_extras.sw_extras as swe
429429
>>> swe.visc(40.0, 40.0, 1000.0)
430-
8.200192496633804e-07
430+
np.float64(8.200192496633804e-07)
431431
432432
Modifications: Original 1998/01/19 - Ayal Anis 1998
433433
@@ -466,7 +466,7 @@ def tcond(s, t, p):
466466
--------
467467
>>> import oceans.sw_extras.sw_extras as swe
468468
>>> swe.tcond(35, 20, 0)
469-
0.5972445569999999
469+
np.float64(0.5972445569999999)
470470
471471
References
472472
----------

0 commit comments

Comments
 (0)