From 66797ed176802ed2f8c9d41c25d54cb975e44ffe Mon Sep 17 00:00:00 2001 From: Konstantinos Kavvadias Date: Mon, 5 Feb 2024 02:26:39 +0200 Subject: [PATCH] [Tests] Fix failing tests in 3.12 Use np.isclose() and isinstance() --- enlopy/generate.py | 4 ++-- tests/test_utils.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/enlopy/generate.py b/enlopy/generate.py index 084756a..49b5836 100644 --- a/enlopy/generate.py +++ b/enlopy/generate.py @@ -84,13 +84,13 @@ def gen_load_from_daily_monthly(ML, DWL, DNWL, weight=0.5, year=2015): if not(np.isclose(DWL.sum(), 1) and np.isclose(DNWL.sum(), 1)): raise ValueError('Daily profiles should be normalized') #TODO: Normalize here? - out = make_timeseries(year=year, length=8760, freq='H') # Create empty pandas with datetime index + out = make_timeseries(year=year, length=8760, freq='h') # Create empty pandas with datetime index import calendar febdays = 29 if calendar.isleap(year) else 28 Days = np.array([31, febdays, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) # Assumptions for non working days per month. Only weekends # TODO: Custom Calendars with holidays BDays - DaysNW = countweekend_days_per_month(out.resample('d').mean()) + DaysNW = countweekend_days_per_month(out.resample('D').mean()) DaysW = Days - DaysNW for month in range(12): # Estimate total load for working and non working day diff --git a/tests/test_utils.py b/tests/test_utils.py index d605c0b..e4523e3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,45 +10,45 @@ def test_ndarray_h(self): a = np.random.rand(8760) b = make_timeseries(a) assert isinstance(b, pd.Series) - assert sum(a) == sum(b) + assert np.isclose(sum(a), sum(b)) def test_ndarray_15m(self): a = np.random.rand(35040) b = make_timeseries(a) assert isinstance(b, pd.Series) - assert sum(a) == sum(b) + assert np.isclose(sum(a), sum(b)) def test_ndarray_x(self): a = np.random.rand(8730) b = make_timeseries(a, freq='h') assert isinstance(b, pd.Series) - assert sum(a) == sum(b) + assert np.isclose(sum(a), sum(b)) def test_pdseries(self): a = pd.Series(np.random.rand(8760)) b = make_timeseries(a) assert isinstance(b, pd.Series) - assert sum(a) == sum(b) + assert np.isclose(sum(a), sum(b)) def test_pddataframe(self): a = pd.DataFrame(np.random.rand(8760)) b = make_timeseries(a) - assert type(b) == pd.DataFrame + assert isinstance(b, pd.DataFrame) def test_pddataframe_2d(self): a = pd.DataFrame(np.random.rand(35040,3)) b = make_timeseries(a) - assert type(b) == pd.DataFrame + assert isinstance(b, pd.DataFrame) def test_2d_ndarray(self): a = np.random.rand(8760,5) b = make_timeseries(a) - assert type(b) == pd.DataFrame + assert isinstance(b, pd.DataFrame) def test_empty_frame(self): a = np.array([]) b = make_timeseries(a, freq='h') - assert type(b) == pd.Series and len(b)==0 + assert isinstance(b, pd.Series) and len(b)==0 def test_empty_frame_to_indexed_empty(self): b = make_timeseries(freq='h', length=8760) @@ -58,7 +58,7 @@ def test_multiannual_timeseries(self): a = np.random.rand(8760*2) b = make_timeseries(a, freq='h') assert isinstance(b, pd.Series) - assert sum(a) == sum(b) + assert np.isclose(sum(a), sum(b)) class Test_clean_convert():