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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)