Skip to content

Commit

Permalink
[Tests] Fix failing tests in 3.12
Browse files Browse the repository at this point in the history
 Use np.isclose() and isinstance()
  • Loading branch information
kavvkon committed Feb 5, 2024
1 parent cf52ac8 commit 66797ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions enlopy/generate.py
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/test_utils.py
Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 66797ed

Please sign in to comment.