Skip to content

Commit 8057393

Browse files
authored
Address several numpy/pandas deprecation warnings; clean up test output (#1930)
* install pytest-remotedata from conda-forge The version in default channel is old. Version in conda-forge is up to date and contains a fix for this deprecation warning: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. * nix `unit='T'` in pd.to_timedelta Use `unit='minutes'` instead of `unit='T'` ('T' was deprecated in pandas 2.1). Fixes: FutureWarning: Unit 'T' is deprecated and will be removed in a future version. * Fix StringIO error regex for python 3.12 * use iloc with pandas Series Fixes: FutureWarning: Series.__setitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To set a value by position, use `ser.iloc[pos] = value` * use pandas bfill()/ffill() instead of fillna(method='...') Fixes: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead. * avoid incompatible dtypes in solarposition.ephemeris Fixes: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[69.43454873]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first. * convert np array of length 1 to scalar Fixes: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.) * use numpy.errstate in bifacial.utils tests Fixes: RuntimeWarning: invalid value encountered in multiply RuntimeWarning: invalid value encountered in scalar multiply * Fix another pandas iloc warning Fixes: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
1 parent 12ba8ee commit 8057393

14 files changed

+29
-21
lines changed

ci/requirements-py3.10.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.10
2222
- pytz
2323
- requests

ci/requirements-py3.11.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.11
2222
- pytz
2323
- requests

ci/requirements-py3.12.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.12
2222
- pytz
2323
- requests

ci/requirements-py3.7.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.7
2222
- pytz
2323
- requests

ci/requirements-py3.8.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.8
2222
- pytz
2323
- requests

ci/requirements-py3.9.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- requests-mock
1818
- pytest-timeout
1919
- pytest-rerunfailures
20-
- pytest-remotedata
20+
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.9
2222
- pytz
2323
- requests

pvlib/iotools/bsrn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def parse_bsrn(fbuf, logical_records=('0100',)):
321321
LR_0100.columns = BSRN_LR0100_COLUMNS
322322
# Set datetime index
323323
LR_0100.index = (start_date+pd.to_timedelta(LR_0100['day']-1, unit='d')
324-
+ pd.to_timedelta(LR_0100['minute'], unit='T'))
324+
+ pd.to_timedelta(LR_0100['minute'], unit='minutes'))
325325
# Drop empty, minute, and day columns
326326
LR_0100 = LR_0100.drop(columns=['empty', 'day', 'minute'])
327327
dfs.append(LR_0100)
@@ -335,7 +335,7 @@ def parse_bsrn(fbuf, logical_records=('0100',)):
335335
colspecs=BSRN_LR0300_COL_SPECS,
336336
names=BSRN_LR0300_COLUMNS)
337337
LR_0300.index = (start_date+pd.to_timedelta(LR_0300['day']-1, unit='d')
338-
+ pd.to_timedelta(LR_0300['minute'], unit='T'))
338+
+ pd.to_timedelta(LR_0300['minute'], unit='minutes'))
339339
LR_0300 = LR_0300.drop(columns=['day', 'minute']).astype(float)
340340
dfs.append(LR_0300)
341341

@@ -352,7 +352,7 @@ def parse_bsrn(fbuf, logical_records=('0100',)):
352352
LR_0500 = LR_0500.reindex(sorted(LR_0500.columns), axis='columns')
353353
LR_0500.columns = BSRN_LR0500_COLUMNS
354354
LR_0500.index = (start_date+pd.to_timedelta(LR_0500['day']-1, unit='d')
355-
+ pd.to_timedelta(LR_0500['minute'], unit='T'))
355+
+ pd.to_timedelta(LR_0500['minute'], unit='minutes'))
356356
LR_0500 = LR_0500.drop(columns=['empty', 'day', 'minute'])
357357
dfs.append(LR_0500)
358358

pvlib/ivtools/sdm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def _fit_desoto_sandia_diode(ee, voc, vth, tc, specs, const):
680680
y = voc - specs['beta_voc'] * (tc - const['T0'])
681681
new_x = sm.add_constant(x)
682682
res = sm.RLM(y, new_x).fit()
683-
return res.params[1]
683+
return np.array(res.params)[1]
684684

685685

686686
def _initial_iv_params(ivcurves, ee, voc, isc, rsh, nnsvth):

pvlib/scaling.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def fn(x):
134134
return np.abs((x ** 2 - x) / 2 - n_pairs)
135135

136136
n_dist = np.round(scipy.optimize.fmin(fn, np.sqrt(n_pairs), disp=False))
137+
n_dist = n_dist.item()
137138
# Compute VR
138139
A = cloud_speed / 2 # Resultant fit for A from [2]
139140
vr = np.zeros(tmscales.shape)
@@ -276,7 +277,7 @@ def _compute_wavelet(clearsky_index, dt=None):
276277
# Produces slightly different end effects than the MATLAB version
277278
df = cs_long.rolling(window=intvlen, center=True, min_periods=1).mean()
278279
# Fill nan's in both directions
279-
df = df.fillna(method='bfill').fillna(method='ffill')
280+
df = df.bfill().ffill()
280281
# Pop values back out of the dataframe and store
281282
csi_mean[i, :] = df.values.flatten()
282283
# Shift to account for different indexing in MATLAB moving average

pvlib/snow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def fully_covered_nrel(snowfall, threshold_snowfall=1.):
5353
freq = pd.infer_freq(snowfall.index)
5454
if freq is not None:
5555
timedelta = pd.tseries.frequencies.to_offset(freq) / pd.Timedelta('1h')
56-
hourly_snow_rate.iloc[0] = snowfall[0] / timedelta
56+
hourly_snow_rate.iloc[0] = snowfall.iloc[0] / timedelta
5757
else: # can't infer frequency from index
58-
hourly_snow_rate[0] = 0 # replaces NaN
58+
hourly_snow_rate.iloc[0] = 0 # replaces NaN
5959
return hourly_snow_rate > threshold_snowfall
6060

6161

pvlib/soiling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def hsu(rainfall, cleaning_threshold, surface_tilt, pm2_5, pm10,
9191
mass_no_cleaning = pd.Series(index=rainfall.index, data=tms_cumsum)
9292
# specify dtype so pandas doesn't assume object
9393
mass_removed = pd.Series(index=rainfall.index, dtype='float64')
94-
mass_removed[0] = 0.
94+
mass_removed.iloc[0] = 0.
9595
mass_removed[cleaning_times] = mass_no_cleaning[cleaning_times]
9696
accum_mass = mass_no_cleaning - mass_removed.ffill()
9797

pvlib/solarposition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def ephemeris(time, latitude, longitude, pressure=101325, temperature=12):
832832
# Calculate refraction correction
833833
Elevation = SunEl
834834
TanEl = pd.Series(np.tan(np.radians(Elevation)), index=time_utc)
835-
Refract = pd.Series(0, index=time_utc)
835+
Refract = pd.Series(0., index=time_utc)
836836

837837
Refract[(Elevation > 5) & (Elevation <= 85)] = (
838838
58.1/TanEl - 0.07/(TanEl**3) + 8.6e-05/(TanEl**5))

pvlib/tests/bifacial/test_utils.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ def test_vf_row_sky_2d(test_system_fixed_tilt):
120120
def test_vf_row_sky_2d_integ(test_system_fixed_tilt):
121121
ts, _, _ = test_system_fixed_tilt
122122
# with float input, check end position
123-
vf = utils.vf_row_sky_2d_integ(ts['surface_tilt'], ts['gcr'], 1., 1.)
123+
with np.errstate(invalid='ignore'):
124+
vf = utils.vf_row_sky_2d_integ(ts['surface_tilt'], ts['gcr'], 1., 1.)
124125
expected = utils.vf_row_sky_2d(ts['surface_tilt'], ts['gcr'], 1.)
125126
assert np.isclose(vf, expected)
126127
# with array input
127128
fx0 = np.array([0., 0.5])
128129
fx1 = np.array([0., 0.8])
129-
vf = utils.vf_row_sky_2d_integ(ts['surface_tilt'], ts['gcr'], fx0, fx1)
130+
with np.errstate(invalid='ignore'):
131+
vf = utils.vf_row_sky_2d_integ(ts['surface_tilt'], ts['gcr'], fx0, fx1)
130132
phi = masking_angle(ts['surface_tilt'], ts['gcr'], fx0[0])
131133
y0 = 0.5 * (1 + cosd(ts['surface_tilt'] + phi))
132134
x = np.arange(fx0[1], fx1[1], 1e-4)
@@ -161,13 +163,17 @@ def test_vf_row_ground_2d(test_system_fixed_tilt):
161163
def test_vf_ground_2d_integ(test_system_fixed_tilt):
162164
ts, _, _ = test_system_fixed_tilt
163165
# with float input, check end position
164-
vf = utils.vf_row_ground_2d_integ(ts['surface_tilt'], ts['gcr'], 0., 0.)
166+
with np.errstate(invalid='ignore'):
167+
vf = utils.vf_row_ground_2d_integ(ts['surface_tilt'], ts['gcr'],
168+
0., 0.)
165169
expected = utils.vf_row_ground_2d(ts['surface_tilt'], ts['gcr'], 0.)
166170
assert np.isclose(vf, expected)
167171
# with array input
168172
fx0 = np.array([0., 0.5])
169173
fx1 = np.array([0., 0.8])
170-
vf = utils.vf_row_ground_2d_integ(ts['surface_tilt'], ts['gcr'], fx0, fx1)
174+
with np.errstate(invalid='ignore'):
175+
vf = utils.vf_row_ground_2d_integ(ts['surface_tilt'], ts['gcr'],
176+
fx0, fx1)
171177
phi = ground_angle(ts['surface_tilt'], ts['gcr'], fx0[0])
172178
y0 = 0.5 * (1 - cosd(phi - ts['surface_tilt']))
173179
x = np.arange(fx0[1], fx1[1], 1e-4)

pvlib/tests/iotools/test_pvgis.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ def test_read_pvgis_hourly_bad_extension():
201201
# Test if ValueError is raised if an unkonwn pvgis_format is specified
202202
with pytest.raises(ValueError, match="pvgis format 'txt' was unknown"):
203203
read_pvgis_hourly(testfile_pv_json, pvgis_format='txt')
204-
# Test if TypeError is raised if input is a buffer and pvgis_format=None
205-
with pytest.raises(TypeError, match="expected str, bytes or os.PathLike"):
204+
# Test if TypeError is raised if input is a buffer and pvgis_format=None.
205+
# The error text changed in python 3.12. This regex matches both versions:
206+
with pytest.raises(TypeError, match="str.*os.PathLike"):
206207
read_pvgis_hourly(io.StringIO())
207208

208209

0 commit comments

Comments
 (0)