Skip to content

Commit

Permalink
pd deprecations in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Sep 11, 2024
1 parent 2d2c7c4 commit 2ae914e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion rdtools/test/clearsky_temperature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_with_tricky_timezones():
tz = 'America/Santiago'
start_date = datetime.datetime(2018, 8, 10, 0, 0, 0)
end_date = datetime.datetime(2018, 8, 14, 23, 0, 0)
freq = 'H'
freq = "h"
lat = -24
lon = -70

Expand Down
8 changes: 3 additions & 5 deletions rdtools/test/degradation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_corr_energy(cls, rd, input_freq):
daily_rd = rd / 365.0

start = '2012-01-01'
if input_freq == 'S':
if input_freq == "s":
end = '2012-03-01'
else:
end = '2015-01-01'
Expand Down Expand Up @@ -53,12 +53,10 @@ def setUpClass(cls):
# define module constants and parameters

# All frequencies
cls.list_all_input_freq = ['MS', 'M', 'W',
'D', 'H', 'T', 'S', 'Irregular_D']
cls.list_all_input_freq = ["MS", "M", "W", "D", "h", "min", "s", "Irregular_D"]

# Allowed frequencies for degradation_ols
cls.list_ols_input_freq = ['MS', 'M', 'W',
'D', 'H', 'T', 'S', 'Irregular_D']
cls.list_ols_input_freq = ["MS", "M", "W", "D", "h", "min", "s", "Irregular_D"]

'''
Allowed frequencies for degradation_classical_decomposition
Expand Down
24 changes: 11 additions & 13 deletions rdtools/test/energy_from_power_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.fixture
def times():
return pd.date_range(start="20200101 12:00", end="20200101 13:00", freq="15T")
return pd.date_range(start="20200101 12:00", end="20200101 13:00", freq="15min")


@pytest.fixture
Expand Down Expand Up @@ -48,50 +48,48 @@ def test_energy_from_power_max_timedelta(power):


def test_energy_from_power_upsample(power):
expected = power.resample("10T").asfreq().interpolate() / 6
expected = power.resample("10min").asfreq().interpolate() / 6
expected = expected.iloc[1:]
expected.name = "energy_Wh"
result = energy_from_power(power, target_frequency="10T")
result = energy_from_power(power, target_frequency="10min")
pd.testing.assert_series_equal(result, expected)


def test_energy_from_power_downsample(power):
expected = power.resample("20T").asfreq()
expected = power.resample("20min").asfreq()
expected = expected.iloc[1:]
expected = pd.Series([0.75, 0.833333333, 0.416666667], index=expected.index)
expected.name = "energy_Wh"
result = energy_from_power(power, target_frequency="20T")
result = energy_from_power(power, target_frequency="20min")
pd.testing.assert_series_equal(result, expected)


def test_energy_from_power_max_timedelta_edge_case():
times = pd.date_range("2020-01-01 12:00", periods=4, freq="15T")
times = pd.date_range("2020-01-01 12:00", periods=4, freq="15min")
power = pd.Series(1, index=times)
power = power.drop(power.index[2])
result = energy_from_power(
power, "30T", max_timedelta=pd.to_timedelta("20 minutes")
)
result = energy_from_power(power, "30min", max_timedelta=pd.to_timedelta("20 minutes"))
assert result.isnull().all()


def test_energy_from_power_single_value_input():
times = pd.date_range("2019-01-01", freq="15T", periods=1)
times = pd.date_range("2019-01-01", freq="15min", periods=1)
power = pd.Series([100.0], index=times)
expected_result = pd.Series([25.0], index=times, name="energy_Wh")
result = energy_from_power(power)
pd.testing.assert_series_equal(result, expected_result)


def test_energy_from_power_single_value_input_no_freq():
power = pd.Series([1], pd.date_range("2019-01-01", periods=1, freq="15T"))
power = pd.Series([1], pd.date_range("2019-01-01", periods=1, freq="15min"))
power.index.freq = None
match = "Could not determine period of input power"
with pytest.raises(ValueError, match=match):
energy_from_power(power)


def test_energy_from_power_single_value_instantaneous():
power = pd.Series([1], pd.date_range("2019-01-01", periods=1, freq="15T"))
power = pd.Series([1], pd.date_range("2019-01-01", periods=1, freq="15min"))
power.index.freq = None
match = (
"power_type='instantaneous' is incompatible with single element power. "
Expand All @@ -102,7 +100,7 @@ def test_energy_from_power_single_value_instantaneous():


def test_energy_from_power_single_value_with_target():
times = pd.date_range("2019-01-01", freq="15T", periods=1)
times = pd.date_range("2019-01-01", freq="15min", periods=1)
power = pd.Series([100.0], index=times)
expected_result = pd.Series([100.0], index=times, name="energy_Wh")
result = energy_from_power(power, target_frequency="H")
Expand Down
8 changes: 3 additions & 5 deletions rdtools/test/filtering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def generate_power_time_series_no_clipping():
power_no_datetime_index = pd.Series(np.arange(1, 101))
power_datetime_index = pd.Series(np.arange(1, 101))
# Add datetime index to second series
time_range = pd.date_range('2016-12-02T11:00:00.000Z',
'2017-06-06T07:00:00.000Z', freq='H')
time_range = pd.date_range("2016-12-02T11:00:00.000Z", "2017-06-06T07:00:00.000Z", freq="h")
power_datetime_index.index = pd.to_datetime(time_range[:100])
# Create a series that is tz-naive to test on
power_datetime_index_tz_naive = power_datetime_index.copy()
Expand Down Expand Up @@ -174,8 +173,7 @@ def generate_power_time_series_clipping():
power_no_datetime_index = power_no_datetime_index.reset_index(drop=True)
power_datetime_index = power_no_datetime_index.copy()
# Add datetime index to second series
time_range = pd.date_range('2016-12-02T11:00:00.000Z',
'2017-06-06T07:00:00.000Z', freq='H')
time_range = pd.date_range("2016-12-02T11:00:00.000Z", "2017-06-06T07:00:00.000Z", freq="h")
power_datetime_index.index = pd.to_datetime(time_range[:100])
# Note: Power is expected to be Series object with a datetime index.
return power_no_datetime_index, power_datetime_index
Expand Down Expand Up @@ -506,7 +504,7 @@ def test_directional_tukey_filter():

def test_hour_angle_filter():
# Create a pandas Series with 5 entries and 15 min index
index = pd.date_range(start='29/04/2022 15:00', periods=5, freq='H')
index = pd.date_range(start="29/04/2022 15:00", periods=5, freq="h")
series = pd.Series([1, 2, 3, 4, 5], index=index)

# Define latitude and longitude
Expand Down
4 changes: 2 additions & 2 deletions rdtools/test/interpolate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

@pytest.fixture
def time_series():
times = pd.date_range("2018-04-01 12:00", "2018-04-01 13:15", freq="15T")
times = pd.date_range("2018-04-01 12:00", "2018-04-01 13:15", freq="15min")
time_series = pd.Series(data=[9, 6, 3, 3, 6, 9], index=times, name="foo")
time_series = time_series.drop(times[4])
return time_series


@pytest.fixture
def target_index(time_series):
return pd.date_range(time_series.index.min(), time_series.index.max(), freq="20T")
return pd.date_range(time_series.index.min(), time_series.index.max(), freq="20min")


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion rdtools/test/irradiance_rescale_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@pytest.fixture
def simple_irradiance():
times = pd.date_range("2019-06-01 12:00", freq="15T", periods=5)
times = pd.date_range("2019-06-01 12:00", freq="15min", periods=5)
time_series = pd.Series([1, 2, 3, 4, 5], index=times, dtype=float)
return time_series

Expand Down
4 changes: 2 additions & 2 deletions rdtools/test/normalize_with_expected_power_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

@pytest.fixture()
def times_15():
return pd.date_range(start='20200101 12:00', end='20200101 13:00', freq='15T')
return pd.date_range(start="20200101 12:00", end="20200101 13:00", freq="15min")


@pytest.fixture()
def times_30():
return pd.date_range(start='20200101 12:00', end='20200101 13:00', freq='30T')
return pd.date_range(start="20200101 12:00", end="20200101 13:00", freq="30min")


@pytest.fixture()
Expand Down
3 changes: 1 addition & 2 deletions rdtools/test/plotting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def test_soiling_rate_histogram_kwargs(soiling_info):
def clipping_power_degradation_signal():
clipping_power_series = pd.Series(np.arange(1, 101))
# Add datetime index to second series
time_range = pd.date_range('2016-12-02T11:00:00.000Z',
'2017-06-06T07:00:00.000Z', freq='H')
time_range = pd.date_range("2016-12-02T11:00:00.000Z", "2017-06-06T07:00:00.000Z", freq="h")
clipping_power_series.index = pd.to_datetime(time_range[:100])
return clipping_power_series

Expand Down

0 comments on commit 2ae914e

Please sign in to comment.