Skip to content

Commit f787047

Browse files
authored
Address pandas deprecation warnings (#1995)
* address the many pandas deprecation warnings * roll back the change from M to ME looks like ME only exists for pandas 2.2+ * lint
1 parent c90cb4e commit f787047

14 files changed

+69
-73
lines changed

pvlib/inverter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ def extract_c(x_d, add):
532532
p_s0 = solve_quad(a, b, c)
533533

534534
# Add values to dataframe at index d
535-
coeffs['a'][d] = a
536-
coeffs['p_dc'][d] = p_dc
537-
coeffs['p_s0'][d] = p_s0
535+
coeffs.loc[d, 'a'] = a
536+
coeffs.loc[d, 'p_dc'] = p_dc
537+
coeffs.loc[d, 'p_s0'] = p_s0
538538

539539
b_dc0, b_dc1, c1 = extract_c(x_d, coeffs['p_dc'])
540540
b_s0, b_s1, c2 = extract_c(x_d, coeffs['p_s0'])

pvlib/iotools/solcast.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,9 @@ def _solcast2pvlib(data):
413413
a pandas.DataFrame with the data cast to pvlib's conventions
414414
"""
415415
# move from period_end to period_middle as per pvlib convention
416-
# to support Pandas 0.25 we cast PTXX to XX as ISO8601
417-
# durations without days aren't supported:
418-
# https://github.com/pandas-dev/pandas/pull/37159\
419-
# Can remove once minimum supported Pandas version is >=1.2
420-
periods = data.period.str.replace("PT", "").str.replace("M", "m")
421416

422417
data["period_mid"] = pd.to_datetime(
423-
data.period_end) - pd.to_timedelta(periods) / 2
418+
data.period_end) - pd.to_timedelta(data.period.values) / 2
424419
data = data.set_index("period_mid").drop(columns=["period_end", "period"])
425420

426421
# rename and convert variables

pvlib/iotools/surfrad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def read_surfrad(filename, map_variables=True):
146146
metadata['surfrad_version'] = int(metadata_list[-1])
147147
metadata['tz'] = 'UTC'
148148

149-
data = pd.read_csv(file_buffer, delim_whitespace=True,
149+
data = pd.read_csv(file_buffer, sep=r'\s+',
150150
header=None, names=SURFRAD_COLUMNS)
151151
file_buffer.close()
152152

pvlib/tests/iotools/test_sodapro.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
testfile_radiation_monthly = DATA_DIR / 'cams_radiation_monthly.csv'
1818

1919

20-
index_verbose = pd.date_range('2020-06-01 12', periods=4, freq='1T', tz='UTC')
20+
index_verbose = pd.date_range('2020-06-01 12', periods=4, freq='1min',
21+
tz='UTC')
2122
index_monthly = pd.date_range('2020-01-01', periods=4, freq='1M')
2223

2324

pvlib/tests/test_clearsky.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def test__calc_stats(detect_clearsky_helper_data):
745745
def test_bird():
746746
"""Test Bird/Hulstrom Clearsky Model"""
747747
times = pd.date_range(start='1/1/2015 0:00', end='12/31/2015 23:00',
748-
freq='H')
748+
freq='h')
749749
tz = -7 # test timezone
750750
gmt_tz = pytz.timezone('Etc/GMT%+d' % -(tz))
751751
times = times.tz_localize(gmt_tz) # set timezone

pvlib/tests/test_irradiance.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@pytest.fixture
2828
def times():
2929
# must include night values
30-
return pd.date_range(start='20140624', freq='6H', periods=4,
30+
return pd.date_range(start='20140624', freq='6h', periods=4,
3131
tz='US/Arizona')
3232

3333

@@ -349,7 +349,7 @@ def test_perez_driesse_components(irrad_data, ephem_data, dni_et,
349349

350350

351351
def test_perez_negative_horizon():
352-
times = pd.date_range(start='20190101 11:30:00', freq='1H',
352+
times = pd.date_range(start='20190101 11:30:00', freq='1h',
353353
periods=5, tz='US/Central')
354354

355355
# Avoid test dependencies on functionality not being tested by hard-coding
@@ -711,7 +711,7 @@ def test_dirint_value():
711711

712712

713713
def test_dirint_nans():
714-
times = pd.date_range(start='2014-06-24T12-0700', periods=5, freq='6H')
714+
times = pd.date_range(start='2014-06-24T12-0700', periods=5, freq='6h')
715715
ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times)
716716
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567], index=times)
717717
pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times)
@@ -1226,7 +1226,7 @@ def test_clearsky_index():
12261226
expected = 0.01
12271227
assert_allclose(out, expected, atol=0.001)
12281228
# series
1229-
times = pd.date_range(start='20180601', periods=2, freq='12H')
1229+
times = pd.date_range(start='20180601', periods=2, freq='12h')
12301230
ghi_measured = pd.Series([100, 500], index=times)
12311231
ghi_modeled = pd.Series([500, 1000], index=times)
12321232
out = irradiance.clearsky_index(ghi_measured, ghi_modeled)
@@ -1282,7 +1282,7 @@ def test_clearness_index():
12821282
expected = 0.725
12831283
assert_allclose(out, expected, atol=0.001)
12841284
# series
1285-
times = pd.date_range(start='20180601', periods=2, freq='12H')
1285+
times = pd.date_range(start='20180601', periods=2, freq='12h')
12861286
ghi = pd.Series([0, 1000], index=times)
12871287
solar_zenith = pd.Series([90, 0], index=times)
12881288
extra_radiation = pd.Series([1360, 1400], index=times)
@@ -1316,7 +1316,7 @@ def test_clearness_index_zenith_independent(airmass_kt):
13161316
expected = 0.443
13171317
assert_allclose(out, expected, atol=0.001)
13181318
# series
1319-
times = pd.date_range(start='20180601', periods=2, freq='12H')
1319+
times = pd.date_range(start='20180601', periods=2, freq='12h')
13201320
clearness_index = pd.Series([0, .5], index=times)
13211321
airmass = pd.Series([np.nan, 2], index=times)
13221322
out = irradiance.clearness_index_zenith_independent(clearness_index,
@@ -1327,7 +1327,7 @@ def test_clearness_index_zenith_independent(airmass_kt):
13271327

13281328
def test_complete_irradiance():
13291329
# Generate dataframe to test on
1330-
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
1330+
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='h')
13311331
i = pd.DataFrame({'ghi': [372.103976116, 497.087579068],
13321332
'dhi': [356.543700, 465.44400],
13331333
'dni': [49.63565561689957, 62.10624908037814]},

pvlib/tests/test_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_location_print_pytz():
7474
def times():
7575
return pd.date_range(start='20160101T0600-0700',
7676
end='20160101T1800-0700',
77-
freq='3H')
77+
freq='3h')
7878

7979

8080
def test_get_clearsky(mocker, times):

pvlib/tests/test_modelchain.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def location():
268268

269269
@pytest.fixture
270270
def weather():
271-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
271+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
272272
weather = pd.DataFrame({'ghi': [500, 0], 'dni': [800, 0], 'dhi': [100, 0]},
273273
index=times)
274274
return weather
@@ -350,7 +350,7 @@ def test_with_pvwatts(pvwatts_dc_pvwatts_ac_system, location, weather):
350350

351351
def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location):
352352
mc = ModelChain(sapm_dc_snl_ac_system, location)
353-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
353+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
354354
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
355355
index=times)
356356
ac = mc.run_model(irradiance).results.ac
@@ -417,7 +417,7 @@ def test_run_model_from_irradiance_arrays_no_loss(
417417
spectral_model='no_loss',
418418
losses_model='no_loss'
419419
)
420-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
420+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
421421
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
422422
index=times)
423423
mc_one.run_model(irradiance)
@@ -457,7 +457,7 @@ def test_run_model_from_irradiance_arrays_no_loss_input_type(
457457
spectral_model='no_loss',
458458
losses_model='no_loss'
459459
)
460-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
460+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
461461
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
462462
index=times)
463463
mc_one.run_model(irradiance)
@@ -487,7 +487,7 @@ def test_ModelChain_invalid_inverter_params_arrays(
487487
def test_prepare_inputs_multi_weather(
488488
sapm_dc_snl_ac_system_Array, location, input_type):
489489
times = pd.date_range(start='20160101 1200-0700',
490-
end='20160101 1800-0700', freq='6H')
490+
end='20160101 1800-0700', freq='6h')
491491
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
492492
weather = pd.DataFrame({'ghi': 1, 'dhi': 1, 'dni': 1},
493493
index=times)
@@ -502,7 +502,7 @@ def test_prepare_inputs_multi_weather(
502502
def test_prepare_inputs_albedo_in_weather(
503503
sapm_dc_snl_ac_system_Array, location, input_type):
504504
times = pd.date_range(start='20160101 1200-0700',
505-
end='20160101 1800-0700', freq='6H')
505+
end='20160101 1800-0700', freq='6h')
506506
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
507507
weather = pd.DataFrame({'ghi': 1, 'dhi': 1, 'dni': 1, 'albedo': 0.5},
508508
index=times)
@@ -564,14 +564,14 @@ def test_ModelChain_times_error_arrays(sapm_dc_snl_ac_system_Array, location):
564564
error_str = r"Input DataFrames must have same index\."
565565
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
566566
irradiance = {'ghi': [1, 2], 'dhi': [1, 2], 'dni': [1, 2]}
567-
times_one = pd.date_range(start='1/1/2020', freq='6H', periods=2)
568-
times_two = pd.date_range(start='1/1/2020 00:15', freq='6H', periods=2)
567+
times_one = pd.date_range(start='1/1/2020', freq='6h', periods=2)
568+
times_two = pd.date_range(start='1/1/2020 00:15', freq='6h', periods=2)
569569
weather_one = pd.DataFrame(irradiance, index=times_one)
570570
weather_two = pd.DataFrame(irradiance, index=times_two)
571571
with pytest.raises(ValueError, match=error_str):
572572
mc.prepare_inputs((weather_one, weather_two))
573573
# test with overlapping, but differently sized indices.
574-
times_three = pd.date_range(start='1/1/2020', freq='6H', periods=3)
574+
times_three = pd.date_range(start='1/1/2020', freq='6h', periods=3)
575575
irradiance_three = irradiance
576576
irradiance_three['ghi'].append(3)
577577
irradiance_three['dhi'].append(3)
@@ -588,7 +588,7 @@ def test_ModelChain_times_arrays(sapm_dc_snl_ac_system_Array, location):
588588
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
589589
irradiance_one = {'ghi': [1, 2], 'dhi': [1, 2], 'dni': [1, 2]}
590590
irradiance_two = {'ghi': [2, 1], 'dhi': [2, 1], 'dni': [2, 1]}
591-
times = pd.date_range(start='1/1/2020', freq='6H', periods=2)
591+
times = pd.date_range(start='1/1/2020', freq='6h', periods=2)
592592
weather_one = pd.DataFrame(irradiance_one, index=times)
593593
weather_two = pd.DataFrame(irradiance_two, index=times)
594594
mc.prepare_inputs((weather_one, weather_two))
@@ -617,7 +617,7 @@ def test_run_model_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
617617
'pvwatts': pvwatts_dc_pvwatts_ac_system_arrays}
618618
mc = ModelChain(system[ac_model], location, aoi_model='no_loss',
619619
spectral_model='no_loss')
620-
times = pd.date_range('20200101 1200-0700', periods=2, freq='2H')
620+
times = pd.date_range('20200101 1200-0700', periods=2, freq='2h')
621621
weather_one = pd.DataFrame({'dni': [900, 800],
622622
'ghi': [600, 500],
623623
'dhi': [150, 100]},
@@ -634,7 +634,7 @@ def test_run_model_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
634634
def test_run_model_perez(sapm_dc_snl_ac_system, location):
635635
mc = ModelChain(sapm_dc_snl_ac_system, location,
636636
transposition_model='perez')
637-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
637+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
638638
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
639639
index=times)
640640
ac = mc.run_model(irradiance).results.ac
@@ -648,7 +648,7 @@ def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location):
648648
mc = ModelChain(sapm_dc_snl_ac_system, location,
649649
airmass_model='gueymard1993',
650650
transposition_model='perez')
651-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
651+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
652652
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
653653
index=times)
654654
ac = mc.run_model(irradiance).results.ac
@@ -812,7 +812,7 @@ def test_prepare_inputs_from_poa_arrays_different_indices(
812812
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
813813
poa = pd.concat([weather, total_irrad], axis=1)
814814
with pytest.raises(ValueError, match=error_str):
815-
mc.prepare_inputs_from_poa((poa, poa.shift(periods=1, freq='6H')))
815+
mc.prepare_inputs_from_poa((poa, poa.shift(periods=1, freq='6h')))
816816

817817

818818
def test_prepare_inputs_from_poa_arrays_missing_column(
@@ -1078,7 +1078,7 @@ def test_run_model_from_effective_irradiance_arrays_error(
10781078
with pytest.raises(ValueError,
10791079
match=r"Input DataFrames must have same index\."):
10801080
mc.run_model_from_effective_irradiance(
1081-
(data, data.shift(periods=1, freq='6H'))
1081+
(data, data.shift(periods=1, freq='6h'))
10821082
)
10831083

10841084

@@ -1790,7 +1790,7 @@ def test_ModelChain_no_extra_kwargs(sapm_dc_snl_ac_system, location):
17901790
def test_basic_chain_alt_az(sam_data, cec_inverter_parameters,
17911791
sapm_temperature_cs5p_220m):
17921792
times = pd.date_range(start='20160101 1200-0700',
1793-
end='20160101 1800-0700', freq='6H')
1793+
end='20160101 1800-0700', freq='6h')
17941794
latitude = 32.2
17951795
longitude = -111
17961796
surface_tilt = 0
@@ -1812,7 +1812,7 @@ def test_basic_chain_alt_az(sam_data, cec_inverter_parameters,
18121812
def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
18131813
sapm_temperature_cs5p_220m):
18141814
times = pd.date_range(start='20160101 1200-0700',
1815-
end='20160101 1800-0700', freq='6H')
1815+
end='20160101 1800-0700', freq='6h')
18161816
latitude = 32.2
18171817
longitude = -111
18181818
altitude = 700
@@ -1847,7 +1847,7 @@ def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
18471847
def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
18481848
"""The DataFrame should not change if all columns are passed"""
18491849
mc = ModelChain(sapm_dc_snl_ac_system, location)
1850-
times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
1850+
times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='h')
18511851
i = pd.DataFrame(
18521852
{'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)
18531853

@@ -1864,7 +1864,7 @@ def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
18641864
def test_complete_irradiance(sapm_dc_snl_ac_system, location, mocker):
18651865
"""Check calculations"""
18661866
mc = ModelChain(sapm_dc_snl_ac_system, location)
1867-
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
1867+
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='h')
18681868
i = pd.DataFrame({'dni': [49.756966, 62.153947],
18691869
'ghi': [372.103976116, 497.087579068],
18701870
'dhi': [356.543700, 465.44400]}, index=times)
@@ -1897,7 +1897,7 @@ def test_complete_irradiance_arrays(
18971897
sapm_dc_snl_ac_system_same_arrays, location, input_type):
18981898
"""ModelChain.complete_irradiance can accept a tuple of weather
18991899
DataFrames."""
1900-
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='H')
1900+
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='h')
19011901
weather = pd.DataFrame({'dni': [2, 3],
19021902
'dhi': [4, 6],
19031903
'ghi': [9, 5]}, index=times)
@@ -1932,7 +1932,7 @@ def test_complete_irradiance_arrays(
19321932
def test_complete_irradiance_arrays_wrong_length(
19331933
sapm_dc_snl_ac_system_same_arrays, location, input_type):
19341934
mc = ModelChain(sapm_dc_snl_ac_system_same_arrays, location)
1935-
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='H')
1935+
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='h')
19361936
weather = pd.DataFrame({'dni': [2, 3],
19371937
'dhi': [4, 6],
19381938
'ghi': [9, 5]}, index=times)

0 commit comments

Comments
 (0)