Skip to content

Commit 1ecef34

Browse files
authored
compatibility with pandas 0.24 deprecations (#662)
* replace DatetimeIndex with date_range * avoid diff on implicit timestamps * update whatsnew
1 parent 594f47c commit 1ecef34

File tree

11 files changed

+66
-86
lines changed

11 files changed

+66
-86
lines changed

docs/sphinx/source/whatsnew/v0.6.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Enhancements
2020

2121
Bug fixes
2222
~~~~~~~~~
23+
* Compatibility with pandas 0.24 deprecations. (:issue:`659`)
2324

2425

2526
Testing
@@ -28,3 +29,5 @@ Testing
2829

2930
Contributors
3031
~~~~~~~~~~~~
32+
* cwhanse
33+
* wholmgren

pvlib/clearsky.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def detect_clearsky(measured, clearsky, times, window_length,
670670
"""
671671

672672
# calculate deltas in units of minutes (matches input window_length units)
673-
deltas = np.diff(times) / np.timedelta64(1, '60s')
673+
deltas = np.diff(times.values) / np.timedelta64(1, '60s')
674674

675675
# determine the unique deltas and if we can proceed
676676
unique_deltas = np.unique(deltas)

pvlib/test/test_atmosphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_airmass(model, expected, zeniths):
4545
assert_allclose(out, expected, equal_nan=True, atol=0.001)
4646
# test series in/out. index does not matter
4747
# hits the isinstance() block in get_relative_airmass
48-
times = pd.DatetimeIndex(start='20180101', periods=len(zeniths), freq='1s')
48+
times = pd.date_range(start='20180101', periods=len(zeniths), freq='1s')
4949
zeniths = pd.Series(zeniths, index=times)
5050
expected = pd.Series(expected, index=times)
5151
out = atmosphere.get_relative_airmass(zeniths, model)

pvlib/test/test_clearsky.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ def test_detect_clearsky_irregular_times(detect_clearsky_data):
619619

620620
def test_bird():
621621
"""Test Bird/Hulstrom Clearsky Model"""
622-
times = pd.DatetimeIndex(start='1/1/2015 0:00', end='12/31/2015 23:00',
623-
freq='H')
622+
times = pd.date_range(start='1/1/2015 0:00', end='12/31/2015 23:00',
623+
freq='H')
624624
tz = -7 # test timezone
625625
gmt_tz = pytz.timezone('Etc/GMT%+d' % -(tz))
626626
times = times.tz_localize(gmt_tz) # set timezone

pvlib/test/test_irradiance.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ def test_disc_overirradiance():
389389
columns = ['dni', 'kt', 'airmass']
390390
ghi = np.array([3000])
391391
solar_zenith = np.full_like(ghi, 0)
392-
times = pd.DatetimeIndex(start='2016-07-19 12:00:00', freq='1s',
393-
periods=len(ghi), tz='America/Phoenix')
392+
times = pd.date_range(start='2016-07-19 12:00:00', freq='1s',
393+
periods=len(ghi), tz='America/Phoenix')
394394
out = irradiance.disc(ghi=ghi, solar_zenith=solar_zenith,
395395
datetime_or_doy=times)
396396
expected = pd.DataFrame(np.array(
@@ -462,7 +462,7 @@ def test_disc_min_cos_zenith_max_zenith():
462462

463463

464464
def test_dirint_value():
465-
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
465+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
466466
ghi = pd.Series([1038.62, 254.53], index=times)
467467
zenith = pd.Series([10.567, 72.469], index=times)
468468
pressure = 93193.
@@ -472,7 +472,7 @@ def test_dirint_value():
472472

473473

474474
def test_dirint_nans():
475-
times = pd.DatetimeIndex(start='2014-06-24T12-0700', periods=5, freq='6H')
475+
times = pd.date_range(start='2014-06-24T12-0700', periods=5, freq='6H')
476476
ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times)
477477
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567], index=times)
478478
pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times)
@@ -797,7 +797,7 @@ def test_clearsky_index():
797797
expected = 0.01
798798
assert_allclose(out, expected, atol=0.001)
799799
# series
800-
times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H')
800+
times = pd.date_range(start='20180601', periods=2, freq='12H')
801801
ghi_measured = pd.Series([100, 500], index=times)
802802
ghi_modeled = pd.Series([500, 1000], index=times)
803803
out = irradiance.clearsky_index(ghi_measured, ghi_modeled)
@@ -853,7 +853,7 @@ def test_clearness_index():
853853
expected = 0.725
854854
assert_allclose(out, expected, atol=0.001)
855855
# series
856-
times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H')
856+
times = pd.date_range(start='20180601', periods=2, freq='12H')
857857
ghi = pd.Series([0, 1000], index=times)
858858
solar_zenith = pd.Series([90, 0], index=times)
859859
extra_radiation = pd.Series([1360, 1400], index=times)
@@ -887,7 +887,7 @@ def test_clearness_index_zenith_independent(airmass_kt):
887887
expected = 0.443
888888
assert_allclose(out, expected, atol=0.001)
889889
# series
890-
times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H')
890+
times = pd.date_range(start='20180601', periods=2, freq='12H')
891891
clearness_index = pd.Series([0, .5], index=times)
892892
airmass = pd.Series([np.nan, 2], index=times)
893893
out = irradiance.clearness_index_zenith_independent(clearness_index,

pvlib/test/test_location.py

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ def test_location_print_pytz():
7575
assert tus.__str__() == expected_str
7676

7777

78+
@pytest.fixture
79+
def times():
80+
return pd.date_range(start='20160101T0600-0700',
81+
end='20160101T1800-0700',
82+
freq='3H')
83+
84+
7885
@requires_scipy
79-
def test_get_clearsky(mocker):
86+
def test_get_clearsky(mocker, times):
8087
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
81-
times = pd.DatetimeIndex(start='20160101T0600-0700',
82-
end='20160101T1800-0700',
83-
freq='3H')
8488
m = mocker.spy(pvlib.clearsky, 'ineichen')
8589
out = tus.get_clearsky(times)
8690
assert m.call_count == 1
@@ -110,11 +114,8 @@ def test_get_clearsky_ineichen_supply_linke(mocker):
110114
assert (out.columns.values == ['ghi', 'dni', 'dhi']).all()
111115

112116

113-
def test_get_clearsky_haurwitz():
117+
def test_get_clearsky_haurwitz(times):
114118
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
115-
times = pd.DatetimeIndex(start='20160101T0600-0700',
116-
end='20160101T1800-0700',
117-
freq='3H')
118119
clearsky = tus.get_clearsky(times, model='haurwitz')
119120
expected = pd.DataFrame(data=np.array(
120121
[[ 0. ],
@@ -127,11 +128,8 @@ def test_get_clearsky_haurwitz():
127128
assert_frame_equal(expected, clearsky)
128129

129130

130-
def test_get_clearsky_simplified_solis():
131+
def test_get_clearsky_simplified_solis(times):
131132
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
132-
times = pd.DatetimeIndex(start='20160101T0600-0700',
133-
end='20160101T1800-0700',
134-
freq='3H')
135133
clearsky = tus.get_clearsky(times, model='simplified_solis')
136134
expected = pd.DataFrame(data=np.
137135
array([[ 0. , 0. , 0. ],
@@ -145,11 +143,8 @@ def test_get_clearsky_simplified_solis():
145143
assert_frame_equal(expected, clearsky, check_less_precise=2)
146144

147145

148-
def test_get_clearsky_simplified_solis_apparent_elevation():
146+
def test_get_clearsky_simplified_solis_apparent_elevation(times):
149147
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
150-
times = pd.DatetimeIndex(start='20160101T0600-0700',
151-
end='20160101T1800-0700',
152-
freq='3H')
153148
solar_position = {'apparent_elevation': pd.Series(80, index=times),
154149
'apparent_zenith': pd.Series(10, index=times)}
155150
clearsky = tus.get_clearsky(times, model='simplified_solis',
@@ -166,11 +161,8 @@ def test_get_clearsky_simplified_solis_apparent_elevation():
166161
assert_frame_equal(expected, clearsky, check_less_precise=2)
167162

168163

169-
def test_get_clearsky_simplified_solis_dni_extra():
164+
def test_get_clearsky_simplified_solis_dni_extra(times):
170165
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
171-
times = pd.DatetimeIndex(start='20160101T0600-0700',
172-
end='20160101T1800-0700',
173-
freq='3H')
174166
clearsky = tus.get_clearsky(times, model='simplified_solis',
175167
dni_extra=1370)
176168
expected = pd.DataFrame(data=np.
@@ -185,11 +177,8 @@ def test_get_clearsky_simplified_solis_dni_extra():
185177
assert_frame_equal(expected, clearsky)
186178

187179

188-
def test_get_clearsky_simplified_solis_pressure():
180+
def test_get_clearsky_simplified_solis_pressure(times):
189181
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
190-
times = pd.DatetimeIndex(start='20160101T0600-0700',
191-
end='20160101T1800-0700',
192-
freq='3H')
193182
clearsky = tus.get_clearsky(times, model='simplified_solis',
194183
pressure=95000)
195184
expected = pd.DataFrame(data=np.
@@ -204,11 +193,8 @@ def test_get_clearsky_simplified_solis_pressure():
204193
assert_frame_equal(expected, clearsky, check_less_precise=2)
205194

206195

207-
def test_get_clearsky_simplified_solis_aod_pw():
196+
def test_get_clearsky_simplified_solis_aod_pw(times):
208197
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
209-
times = pd.DatetimeIndex(start='20160101T0600-0700',
210-
end='20160101T1800-0700',
211-
freq='3H')
212198
clearsky = tus.get_clearsky(times, model='simplified_solis',
213199
aod700=0.25, precipitable_water=2.)
214200
expected = pd.DataFrame(data=np.
@@ -223,11 +209,8 @@ def test_get_clearsky_simplified_solis_aod_pw():
223209
assert_frame_equal(expected, clearsky, check_less_precise=2)
224210

225211

226-
def test_get_clearsky_valueerror():
212+
def test_get_clearsky_valueerror(times):
227213
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
228-
times = pd.DatetimeIndex(start='20160101T0600-0700',
229-
end='20160101T1800-0700',
230-
freq='3H')
231214
with pytest.raises(ValueError):
232215
clearsky = tus.get_clearsky(times, model='invalid_model')
233216

@@ -255,7 +238,7 @@ def test_from_tmy_2():
255238

256239

257240
def test_get_solarposition(expected_solpos, golden_mst):
258-
times = pd.date_range(datetime.datetime(2003,10,17,12,30,30),
241+
times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30),
259242
periods=1, freq='D', tz=golden_mst.tz)
260243
ephem_data = golden_mst.get_solarposition(times, temperature=11)
261244
ephem_data = np.round(ephem_data, 3)
@@ -264,11 +247,8 @@ def test_get_solarposition(expected_solpos, golden_mst):
264247
assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns])
265248

266249

267-
def test_get_airmass():
250+
def test_get_airmass(times):
268251
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
269-
times = pd.DatetimeIndex(start='20160101T0600-0700',
270-
end='20160101T1800-0700',
271-
freq='3H')
272252
airmass = tus.get_airmass(times)
273253
expected = pd.DataFrame(data=np.array(
274254
[[ nan, nan],
@@ -292,11 +272,8 @@ def test_get_airmass():
292272
assert_frame_equal(expected, airmass)
293273

294274

295-
def test_get_airmass_valueerror():
275+
def test_get_airmass_valueerror(times):
296276
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
297-
times = pd.DatetimeIndex(start='20160101T0600-0700',
298-
end='20160101T1800-0700',
299-
freq='3H')
300277
with pytest.raises(ValueError):
301278
clearsky = tus.get_airmass(times, model='invalid_model')
302279

@@ -329,8 +306,8 @@ def test_get_sun_rise_set_transit(golden):
329306
declination = declination_spencer71(dayofyear)
330307
eot = equation_of_time_spencer71(dayofyear)
331308
result = golden.get_sun_rise_set_transit(times, method='geometric',
332-
declination=declination,
333-
equation_of_time=eot)
309+
declination=declination,
310+
equation_of_time=eot)
334311
assert all(result.columns == ['sunrise', 'sunset', 'transit'])
335312

336313

pvlib/test/test_modelchain.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ def test_deprecated_07():
488488

489489
@requires_scipy
490490
def test_basic_chain_required(sam_data):
491-
times = pd.DatetimeIndex(start='20160101 1200-0700',
492-
end='20160101 1800-0700', freq='6H')
491+
times = pd.date_range(start='20160101 1200-0700',
492+
end='20160101 1800-0700', freq='6H')
493493
latitude = 32
494494
longitude = -111
495495
altitude = 700
@@ -505,8 +505,8 @@ def test_basic_chain_required(sam_data):
505505

506506
@requires_scipy
507507
def test_basic_chain_alt_az(sam_data):
508-
times = pd.DatetimeIndex(start='20160101 1200-0700',
509-
end='20160101 1800-0700', freq='6H')
508+
times = pd.date_range(start='20160101 1200-0700',
509+
end='20160101 1800-0700', freq='6H')
510510
latitude = 32.2
511511
longitude = -111
512512
altitude = 700
@@ -529,8 +529,8 @@ def test_basic_chain_alt_az(sam_data):
529529

530530
@requires_scipy
531531
def test_basic_chain_strategy(sam_data):
532-
times = pd.DatetimeIndex(start='20160101 1200-0700',
533-
end='20160101 1800-0700', freq='6H')
532+
times = pd.date_range(start='20160101 1200-0700',
533+
end='20160101 1800-0700', freq='6H')
534534
latitude = 32.2
535535
longitude = -111
536536
altitude = 700
@@ -551,8 +551,8 @@ def test_basic_chain_strategy(sam_data):
551551

552552
@requires_scipy
553553
def test_basic_chain_altitude_pressure(sam_data):
554-
times = pd.DatetimeIndex(start='20160101 1200-0700',
555-
end='20160101 1800-0700', freq='6H')
554+
times = pd.date_range(start='20160101 1200-0700',
555+
end='20160101 1800-0700', freq='6H')
556556
latitude = 32.2
557557
longitude = -111
558558
altitude = 700

pvlib/test/test_pvsystem.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def pvsyst_module_params():
194194

195195
def test_sapm(sapm_module_params):
196196

197-
times = pd.DatetimeIndex(start='2015-01-01', periods=5, freq='12H')
197+
times = pd.date_range(start='2015-01-01', periods=5, freq='12H')
198198
effective_irradiance = pd.Series([-1, 0.5, 1.1, np.nan, 1], index=times)
199199
temp_cell = pd.Series([10, 25, 50, 25, np.nan], index=times)
200200

@@ -380,7 +380,7 @@ def test_PVSystem_sapm_effective_irradiance(sapm_module_params, mocker):
380380

381381

382382
def test_calcparams_desoto(cec_module_params):
383-
times = pd.DatetimeIndex(start='2015-01-01', periods=3, freq='12H')
383+
times = pd.date_range(start='2015-01-01', periods=3, freq='12H')
384384
effective_irradiance = pd.Series([0.0, 800.0, 800.0], index=times)
385385
temp_cell = pd.Series([25, 25, 50], index=times)
386386

@@ -408,7 +408,7 @@ def test_calcparams_desoto(cec_module_params):
408408

409409

410410
def test_calcparams_cec(cec_module_params):
411-
times = pd.DatetimeIndex(start='2015-01-01', periods=3, freq='12H')
411+
times = pd.date_range(start='2015-01-01', periods=3, freq='12H')
412412
effective_irradiance = pd.Series([0.0, 800.0, 800.0], index=times)
413413
temp_cell = pd.Series([25, 25, 50], index=times)
414414

@@ -437,7 +437,7 @@ def test_calcparams_cec(cec_module_params):
437437

438438

439439
def test_calcparams_pvsyst(pvsyst_module_params):
440-
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
440+
times = pd.date_range(start='2015-01-01', periods=2, freq='12H')
441441
effective_irradiance = pd.Series([0.0, 800.0], index=times)
442442
temp_cell = pd.Series([25, 50], index=times)
443443

@@ -868,7 +868,7 @@ def test_mpp_series():
868868

869869
@requires_scipy
870870
def test_singlediode_series(cec_module_params):
871-
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
871+
times = pd.date_range(start='2015-01-01', periods=2, freq='12H')
872872
effective_irradiance = pd.Series([0.0, 800.0], index=times)
873873
IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
874874
effective_irradiance,
@@ -957,7 +957,7 @@ def test_singlediode_floats_ivcurve():
957957

958958
@requires_scipy
959959
def test_singlediode_series_ivcurve(cec_module_params):
960-
times = pd.DatetimeIndex(start='2015-06-01', periods=3, freq='6H')
960+
times = pd.date_range(start='2015-06-01', periods=3, freq='6H')
961961
effective_irradiance = pd.Series([0.0, 400.0, 800.0], index=times)
962962
IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
963963
effective_irradiance,
@@ -1049,7 +1049,7 @@ def test_sapm_celltemp_dict_like():
10491049

10501050

10511051
def test_sapm_celltemp_with_index():
1052-
times = pd.DatetimeIndex(start='2015-01-01', end='2015-01-02', freq='12H')
1052+
times = pd.date_range(start='2015-01-01', end='2015-01-02', freq='12H')
10531053
temps = pd.Series([0, 10, 5], index=times)
10541054
irrads = pd.Series([0, 500, 0], index=times)
10551055
winds = pd.Series([10, 5, 0], index=times)
@@ -1108,7 +1108,7 @@ def test_pvsyst_celltemp_model_non_option():
11081108

11091109

11101110
def test_pvsyst_celltemp_with_index():
1111-
times = pd.DatetimeIndex(start="2015-01-01", end="2015-01-02", freq="12H")
1111+
times = pd.date_range(start="2015-01-01", end="2015-01-02", freq="12H")
11121112
temps = pd.Series([0, 10, 5], index=times)
11131113
irrads = pd.Series([0, 500, 0], index=times)
11141114
winds = pd.Series([10, 5, 0], index=times)
@@ -1244,8 +1244,8 @@ def test_PVSystem_get_aoi():
12441244

12451245
def test_PVSystem_get_irradiance():
12461246
system = pvsystem.PVSystem(surface_tilt=32, surface_azimuth=135)
1247-
times = pd.DatetimeIndex(start='20160101 1200-0700',
1248-
end='20160101 1800-0700', freq='6H')
1247+
times = pd.date_range(start='20160101 1200-0700',
1248+
end='20160101 1800-0700', freq='6H')
12491249
location = Location(latitude=32, longitude=-111)
12501250
solar_position = location.get_solarposition(times)
12511251
irrads = pd.DataFrame({'dni':[900,0], 'ghi':[600,0], 'dhi':[100,0]},

0 commit comments

Comments
 (0)