Skip to content
Open
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
4 changes: 3 additions & 1 deletion docs/sphinx/source/whatsnew/v0.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Bug fixes

Enhancements
~~~~~~~~~~~~
* Add ``pandas==3.1.0`` support. (:pull:`2924`)
* Add ``pandas==3.1.0`` support. (:pull:`2924`, :issue:`2935`, :pull:`2937`)
* Add ``dataset`` parameter to :py:func:`~pvlib.iotools.get_era5`
allowing for choosing between ERA5 and ERA5-Land datasets.
(:pull:`2780`)
Expand Down Expand Up @@ -80,3 +80,5 @@ Contributors
* :ghuser:`bfs2021`
* :ghuser:`xiajiahang`
* Jakub Krasuski (:ghuser:`Blizzeq`)
* S B Pranay (:ghuser:`pranaysb`)
Comment thread
pranaysb marked this conversation as resolved.
Resolved
* :ghuser:`aarmens702-hub`
8 changes: 3 additions & 5 deletions pvlib/soiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@ def kimber(rainfall, cleaning_threshold=6, soiling_loss_rate=0.0015,
# convert grace_period to timedelta
grace_period = datetime.timedelta(days=grace_period)

# get indices as np.datetime64 (UTC), calculate timestep as np.timedelta64,
# and convert timestep to fraction of days
rain_index_vals = rainfall.index.tz_convert(None).to_numpy()
timestep_interval = (rain_index_vals[1] - rain_index_vals[0])
day_fraction = timestep_interval / np.timedelta64(24, 'h')
# calculate timestep as timedelta and convert to fraction of days
timestep_interval = rainfall.index[1] - rainfall.index[0]
day_fraction = timestep_interval / pd.Timedelta(days=1)

# accumulate rainfall
accumulated_rainfall = rainfall.rolling(
Expand Down
8 changes: 2 additions & 6 deletions pvlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,14 @@ def _get_sample_intervals(times, win_length):
""" Calculates time interval and samples per window for Reno-style clear
sky detection functions
"""
deltas = (
np.diff(times.tz_localize(None).to_numpy()) # tz-naive np.datetime64
/ np.timedelta64(1, '60s')
)
deltas = (times[1:] - times[:-1]) / pd.Timedelta('60s')

# determine if we can proceed
if ( # infer wrapper is None if no freq is determined
_pandas_infer_freq_BaseOffset_transition_handler(times)
and len(np.unique(deltas)) == 1
):
sample_interval = times[1] - times[0]
sample_interval = sample_interval.seconds / 60 # in minutes
sample_interval = (times[1] - times[0]).total_seconds() / 60
samples_per_window = int(win_length / sample_interval)
return sample_interval, samples_per_window
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,19 @@ def test_detect_clearsky_optimizer_not_failed(
assert isinstance(clear_samples, pd.Series)


def test_detect_clearsky_dst():
# GH 2935
loc = Location(49.28, -123.12, tz='America/Vancouver')
times = pd.date_range('2026-03-07', '2026-03-10', freq='1min',
tz=loc.tz, inclusive='left')
ghi = loc.get_clearsky(times)['ghi']
result = clearsky.detect_clearsky(ghi, ghi)
result_utc = clearsky.detect_clearsky(
ghi.tz_convert('UTC'), ghi.tz_convert('UTC')
)
assert_series_equal(result, result_utc.tz_convert(loc.tz))


@pytest.fixture
def detect_clearsky_helper_data():
samples_per_window = 3
Expand Down
8 changes: 8 additions & 0 deletions tests/test_soiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ def test_kimber_nowash(greensboro_rain, expected_kimber_nowash):
assert np.allclose(nowash.values, expected_kimber_nowash['soiling'].values)


def test_kimber_tz_naive(greensboro_rain, expected_kimber_nowash):
# GH 2935
rain_naive = greensboro_rain.copy()
rain_naive.index = rain_naive.index.tz_localize(None)
actual = kimber(rain_naive)
assert np.allclose(actual.values, expected_kimber_nowash['soiling'].values)


@pytest.fixture
def expected_kimber_manwash():
return pd.read_csv(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ def test_prilliman_nans():
assert_series_equal(actual, expected)


def test_prilliman_dst():
# GH 2935
times = pd.date_range('2026-03-07', '2026-03-10', freq='1min',
tz='America/Vancouver', inclusive='left')
cell_temperature = pd.Series(25.0, index=times)
wind_speed = pd.Series(1.0, index=times)
actual = temperature.prilliman(cell_temperature, wind_speed)
assert_series_equal(cell_temperature, actual)


def test_glm_conversions():
# it is easiest and sufficient to test conversion from & to the same model
glm = temperature.GenericLinearModel(module_efficiency=0.1,
Expand Down
48 changes: 48 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,51 @@ def test__file_context_manager():
buffer = StringIO("test content")
with tools._file_context_manager(buffer) as obj:
assert obj.read() == "test content"


def test_get_sample_intervals_dst():
# GH 2935
times = pd.date_range('2026-03-07', '2026-03-10', freq='1min',
tz='America/Vancouver')
interval, count = tools._get_sample_intervals(times, 20)
assert interval == 1.0
assert count == 20


def test_get_sample_intervals_dst_fall_back():
# GH 2935
times = pd.date_range('2026-11-01 05:00', periods=8, freq='15min',
tz='UTC').tz_convert('America/New_York')
interval, count = tools._get_sample_intervals(times, 60)
assert interval == 15.0
assert count == 4


def test_get_sample_intervals_naive():
# GH 2935
times = pd.date_range('2026-01-01', periods=60, freq='1min')
interval, count = tools._get_sample_intervals(times, 20)
assert interval == 1.0
assert count == 20


def test_get_sample_intervals_unequal():
Comment thread
pranaysb marked this conversation as resolved.
Resolved
times = pd.DatetimeIndex(['2026-01-01 00:00', '2026-01-01 00:01',
'2026-01-01 00:05'])
with pytest.raises(NotImplementedError, match='unequal time intervals'):
tools._get_sample_intervals(times, 20)


@pytest.mark.parametrize('times', [
# months differ in length
pd.date_range('2026-01-01', periods=4, freq='MS'),
# local midnights: the day of the spring DST change is 23 h long
pd.date_range('2026-03-06', periods=4, freq='D').tz_localize(
'America/Denver'),
])
def test__get_sample_intervals_calendar_freq(times):
# pandas finds a frequency for these, so only the check of the time
# elapsed between samples can reject them
assert tools._pandas_infer_freq_BaseOffset_transition_handler(times)
with pytest.raises(NotImplementedError, match='unequal time intervals'):
tools._get_sample_intervals(times, 20)