Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address pandas deprecation warnings #1995

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pvlib/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ def extract_c(x_d, add):
p_s0 = solve_quad(a, b, c)

# Add values to dataframe at index d
coeffs['a'][d] = a
coeffs['p_dc'][d] = p_dc
coeffs['p_s0'][d] = p_s0
coeffs.loc[d, 'a'] = a
coeffs.loc[d, 'p_dc'] = p_dc
coeffs.loc[d, 'p_s0'] = p_s0

b_dc0, b_dc1, c1 = extract_c(x_d, coeffs['p_dc'])
b_s0, b_s1, c2 = extract_c(x_d, coeffs['p_s0'])
Expand Down
7 changes: 1 addition & 6 deletions pvlib/iotools/solcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,9 @@ def _solcast2pvlib(data):
a pandas.DataFrame with the data cast to pvlib's conventions
"""
# move from period_end to period_middle as per pvlib convention
# to support Pandas 0.25 we cast PTXX to XX as ISO8601
# durations without days aren't supported:
# https://github.com/pandas-dev/pandas/pull/37159\
# Can remove once minimum supported Pandas version is >=1.2
periods = data.period.str.replace("PT", "").str.replace("M", "m")

data["period_mid"] = pd.to_datetime(
data.period_end) - pd.to_timedelta(periods) / 2
data.period_end) - pd.to_timedelta(data.period.values) / 2
data = data.set_index("period_mid").drop(columns=["period_end", "period"])

# rename and convert variables
Expand Down
2 changes: 1 addition & 1 deletion pvlib/iotools/surfrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def read_surfrad(filename, map_variables=True):
metadata['surfrad_version'] = int(metadata_list[-1])
metadata['tz'] = 'UTC'

data = pd.read_csv(file_buffer, delim_whitespace=True,
data = pd.read_csv(file_buffer, sep=r'\s+',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning states:

"FutureWarning: The 'delim_whitespace' keyword in pd.read_csv is deprecated and will be removed in a future version. Use sep='\s+' instead",

Is there a reason that you're using a single backslash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sep='\\s+' is equivalent to sep=r'\s+', I just preferred to use an r string instead of escaping the backslash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured - thanks for letting me know!

header=None, names=SURFRAD_COLUMNS)
file_buffer.close()

Expand Down
3 changes: 2 additions & 1 deletion pvlib/tests/iotools/test_sodapro.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
testfile_radiation_monthly = DATA_DIR / 'cams_radiation_monthly.csv'


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


Expand Down
2 changes: 1 addition & 1 deletion pvlib/tests/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def test__calc_stats(detect_clearsky_helper_data):
def test_bird():
"""Test Bird/Hulstrom Clearsky Model"""
times = pd.date_range(start='1/1/2015 0:00', end='12/31/2015 23:00',
freq='H')
freq='h')
tz = -7 # test timezone
gmt_tz = pytz.timezone('Etc/GMT%+d' % -(tz))
times = times.tz_localize(gmt_tz) # set timezone
Expand Down
14 changes: 7 additions & 7 deletions pvlib/tests/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@pytest.fixture
def times():
# must include night values
return pd.date_range(start='20140624', freq='6H', periods=4,
return pd.date_range(start='20140624', freq='6h', periods=4,
tz='US/Arizona')


Expand Down Expand Up @@ -349,7 +349,7 @@ def test_perez_driesse_components(irrad_data, ephem_data, dni_et,


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

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


def test_dirint_nans():
times = pd.date_range(start='2014-06-24T12-0700', periods=5, freq='6H')
times = pd.date_range(start='2014-06-24T12-0700', periods=5, freq='6h')
ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times)
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567], index=times)
pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times)
Expand Down Expand Up @@ -1226,7 +1226,7 @@ def test_clearsky_index():
expected = 0.01
assert_allclose(out, expected, atol=0.001)
# series
times = pd.date_range(start='20180601', periods=2, freq='12H')
times = pd.date_range(start='20180601', periods=2, freq='12h')
ghi_measured = pd.Series([100, 500], index=times)
ghi_modeled = pd.Series([500, 1000], index=times)
out = irradiance.clearsky_index(ghi_measured, ghi_modeled)
Expand Down Expand Up @@ -1282,7 +1282,7 @@ def test_clearness_index():
expected = 0.725
assert_allclose(out, expected, atol=0.001)
# series
times = pd.date_range(start='20180601', periods=2, freq='12H')
times = pd.date_range(start='20180601', periods=2, freq='12h')
ghi = pd.Series([0, 1000], index=times)
solar_zenith = pd.Series([90, 0], index=times)
extra_radiation = pd.Series([1360, 1400], index=times)
Expand Down Expand Up @@ -1316,7 +1316,7 @@ def test_clearness_index_zenith_independent(airmass_kt):
expected = 0.443
assert_allclose(out, expected, atol=0.001)
# series
times = pd.date_range(start='20180601', periods=2, freq='12H')
times = pd.date_range(start='20180601', periods=2, freq='12h')
clearness_index = pd.Series([0, .5], index=times)
airmass = pd.Series([np.nan, 2], index=times)
out = irradiance.clearness_index_zenith_independent(clearness_index,
Expand All @@ -1327,7 +1327,7 @@ def test_clearness_index_zenith_independent(airmass_kt):

def test_complete_irradiance():
# Generate dataframe to test on
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='h')
i = pd.DataFrame({'ghi': [372.103976116, 497.087579068],
'dhi': [356.543700, 465.44400],
'dni': [49.63565561689957, 62.10624908037814]},
Expand Down
2 changes: 1 addition & 1 deletion pvlib/tests/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_location_print_pytz():
def times():
return pd.date_range(start='20160101T0600-0700',
end='20160101T1800-0700',
freq='3H')
freq='3h')


def test_get_clearsky(mocker, times):
Expand Down
42 changes: 21 additions & 21 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def location():

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

def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location):
mc = ModelChain(sapm_dc_snl_ac_system, location)
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
index=times)
ac = mc.run_model(irradiance).results.ac
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_run_model_from_irradiance_arrays_no_loss(
spectral_model='no_loss',
losses_model='no_loss'
)
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
index=times)
mc_one.run_model(irradiance)
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_run_model_from_irradiance_arrays_no_loss_input_type(
spectral_model='no_loss',
losses_model='no_loss'
)
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
index=times)
mc_one.run_model(irradiance)
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_ModelChain_invalid_inverter_params_arrays(
def test_prepare_inputs_multi_weather(
sapm_dc_snl_ac_system_Array, location, input_type):
times = pd.date_range(start='20160101 1200-0700',
end='20160101 1800-0700', freq='6H')
end='20160101 1800-0700', freq='6h')
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
weather = pd.DataFrame({'ghi': 1, 'dhi': 1, 'dni': 1},
index=times)
Expand All @@ -502,7 +502,7 @@ def test_prepare_inputs_multi_weather(
def test_prepare_inputs_albedo_in_weather(
sapm_dc_snl_ac_system_Array, location, input_type):
times = pd.date_range(start='20160101 1200-0700',
end='20160101 1800-0700', freq='6H')
end='20160101 1800-0700', freq='6h')
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
weather = pd.DataFrame({'ghi': 1, 'dhi': 1, 'dni': 1, 'albedo': 0.5},
index=times)
Expand Down Expand Up @@ -564,14 +564,14 @@ def test_ModelChain_times_error_arrays(sapm_dc_snl_ac_system_Array, location):
error_str = r"Input DataFrames must have same index\."
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
irradiance = {'ghi': [1, 2], 'dhi': [1, 2], 'dni': [1, 2]}
times_one = pd.date_range(start='1/1/2020', freq='6H', periods=2)
times_two = pd.date_range(start='1/1/2020 00:15', freq='6H', periods=2)
times_one = pd.date_range(start='1/1/2020', freq='6h', periods=2)
times_two = pd.date_range(start='1/1/2020 00:15', freq='6h', periods=2)
weather_one = pd.DataFrame(irradiance, index=times_one)
weather_two = pd.DataFrame(irradiance, index=times_two)
with pytest.raises(ValueError, match=error_str):
mc.prepare_inputs((weather_one, weather_two))
# test with overlapping, but differently sized indices.
times_three = pd.date_range(start='1/1/2020', freq='6H', periods=3)
times_three = pd.date_range(start='1/1/2020', freq='6h', periods=3)
irradiance_three = irradiance
irradiance_three['ghi'].append(3)
irradiance_three['dhi'].append(3)
Expand All @@ -588,7 +588,7 @@ def test_ModelChain_times_arrays(sapm_dc_snl_ac_system_Array, location):
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
irradiance_one = {'ghi': [1, 2], 'dhi': [1, 2], 'dni': [1, 2]}
irradiance_two = {'ghi': [2, 1], 'dhi': [2, 1], 'dni': [2, 1]}
times = pd.date_range(start='1/1/2020', freq='6H', periods=2)
times = pd.date_range(start='1/1/2020', freq='6h', periods=2)
weather_one = pd.DataFrame(irradiance_one, index=times)
weather_two = pd.DataFrame(irradiance_two, index=times)
mc.prepare_inputs((weather_one, weather_two))
Expand Down Expand Up @@ -617,7 +617,7 @@ def test_run_model_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
'pvwatts': pvwatts_dc_pvwatts_ac_system_arrays}
mc = ModelChain(system[ac_model], location, aoi_model='no_loss',
spectral_model='no_loss')
times = pd.date_range('20200101 1200-0700', periods=2, freq='2H')
times = pd.date_range('20200101 1200-0700', periods=2, freq='2h')
weather_one = pd.DataFrame({'dni': [900, 800],
'ghi': [600, 500],
'dhi': [150, 100]},
Expand All @@ -634,7 +634,7 @@ def test_run_model_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
def test_run_model_perez(sapm_dc_snl_ac_system, location):
mc = ModelChain(sapm_dc_snl_ac_system, location,
transposition_model='perez')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
index=times)
ac = mc.run_model(irradiance).results.ac
Expand All @@ -648,7 +648,7 @@ def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location):
mc = ModelChain(sapm_dc_snl_ac_system, location,
airmass_model='gueymard1993',
transposition_model='perez')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
index=times)
ac = mc.run_model(irradiance).results.ac
Expand Down Expand Up @@ -812,7 +812,7 @@ def test_prepare_inputs_from_poa_arrays_different_indices(
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
poa = pd.concat([weather, total_irrad], axis=1)
with pytest.raises(ValueError, match=error_str):
mc.prepare_inputs_from_poa((poa, poa.shift(periods=1, freq='6H')))
mc.prepare_inputs_from_poa((poa, poa.shift(periods=1, freq='6h')))


def test_prepare_inputs_from_poa_arrays_missing_column(
Expand Down Expand Up @@ -1078,7 +1078,7 @@ def test_run_model_from_effective_irradiance_arrays_error(
with pytest.raises(ValueError,
match=r"Input DataFrames must have same index\."):
mc.run_model_from_effective_irradiance(
(data, data.shift(periods=1, freq='6H'))
(data, data.shift(periods=1, freq='6h'))
)


Expand Down Expand Up @@ -1790,7 +1790,7 @@ def test_ModelChain_no_extra_kwargs(sapm_dc_snl_ac_system, location):
def test_basic_chain_alt_az(sam_data, cec_inverter_parameters,
sapm_temperature_cs5p_220m):
times = pd.date_range(start='20160101 1200-0700',
end='20160101 1800-0700', freq='6H')
end='20160101 1800-0700', freq='6h')
latitude = 32.2
longitude = -111
surface_tilt = 0
Expand All @@ -1812,7 +1812,7 @@ def test_basic_chain_alt_az(sam_data, cec_inverter_parameters,
def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
sapm_temperature_cs5p_220m):
times = pd.date_range(start='20160101 1200-0700',
end='20160101 1800-0700', freq='6H')
end='20160101 1800-0700', freq='6h')
latitude = 32.2
longitude = -111
altitude = 700
Expand Down Expand Up @@ -1847,7 +1847,7 @@ def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
"""The DataFrame should not change if all columns are passed"""
mc = ModelChain(sapm_dc_snl_ac_system, location)
times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='h')
i = pd.DataFrame(
{'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)

Expand All @@ -1864,7 +1864,7 @@ def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
def test_complete_irradiance(sapm_dc_snl_ac_system, location, mocker):
"""Check calculations"""
mc = ModelChain(sapm_dc_snl_ac_system, location)
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='h')
i = pd.DataFrame({'dni': [49.756966, 62.153947],
'ghi': [372.103976116, 497.087579068],
'dhi': [356.543700, 465.44400]}, index=times)
Expand Down Expand Up @@ -1897,7 +1897,7 @@ def test_complete_irradiance_arrays(
sapm_dc_snl_ac_system_same_arrays, location, input_type):
"""ModelChain.complete_irradiance can accept a tuple of weather
DataFrames."""
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='H')
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='h')
weather = pd.DataFrame({'dni': [2, 3],
'dhi': [4, 6],
'ghi': [9, 5]}, index=times)
Expand Down Expand Up @@ -1932,7 +1932,7 @@ def test_complete_irradiance_arrays(
def test_complete_irradiance_arrays_wrong_length(
sapm_dc_snl_ac_system_same_arrays, location, input_type):
mc = ModelChain(sapm_dc_snl_ac_system_same_arrays, location)
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='H')
times = pd.date_range(start='2020-01-01 0700-0700', periods=2, freq='h')
weather = pd.DataFrame({'dni': [2, 3],
'dhi': [4, 6],
'ghi': [9, 5]}, index=times)
Expand Down
Loading
Loading