Skip to content

Commit

Permalink
Revert "allow incomplete dates"
Browse files Browse the repository at this point in the history
This reverts commit c8b64a2.
  • Loading branch information
elbeejay committed Aug 18, 2023
1 parent c8b64a2 commit 91678d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
14 changes: 2 additions & 12 deletions hyswap/cumulative.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

def calculate_daily_cumulative_values(df, data_column_name,
date_column_name=None,
year_type='calendar',
allow_incomplete_years=True):
year_type='calendar'):
"""Calculate daily cumulative values.
Parameters
Expand All @@ -29,11 +28,6 @@ def calculate_daily_cumulative_values(df, data_column_name,
2011". 'climate' years begin on April 1 and end on March 31 of the
following year, they are numbered by the ending year. For example,
April 1, 2010 to March 31, 2011 is "climate year 2011".
allow_incomplete_years : Boolean, optional
Boolean to allow incomplete years to be computed. By default this is
True, meaning that incomplete years will be calculated. If False, then
no cumulative daily values will be calculated for years which lack
365 days of data.
Returns
-------
Expand Down Expand Up @@ -68,11 +62,7 @@ def calculate_daily_cumulative_values(df, data_column_name,
# get data for the year
year_data = df.loc[df['index_year'] == year, data_column_name]
# year must be complete
if allow_incomplete_years:
# calculate cumulative values and assign to cdf
cdf.loc[cdf.index == year, :len(year_data)] = \
year_data.cumsum().values
elif (allow_incomplete_years is False) and (len(year_data) == 365):
if len(year_data) == 365:
# calculate cumulative values and assign to cdf
cdf.loc[cdf.index == year, :len(year_data)] = \
year_data.cumsum().values
Expand Down
6 changes: 2 additions & 4 deletions tests/test_cumulative.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def test_calculate_daily_cumulative_values_water_year(self):
'data': np.ones(len(pd.date_range('2016-01-01', '2019-12-31'))),
'date': pd.date_range('2016-01-01', '2019-12-31')})
cdf = cumulative.calculate_daily_cumulative_values(
df, 'data', date_column_name='date', year_type='water',
allow_incomplete_years=False)
df, 'data', date_column_name='date', year_type='water')
assert cdf.shape == (365*3, 3)
assert cdf.columns.tolist() == \
['index_year', 'index_doy', 'cumulative']
Expand All @@ -79,8 +78,7 @@ def test_calculate_daily_cumulative_values_climate_year(self):
'data': np.ones(len(pd.date_range('2016-01-01', '2019-12-31'))),
'date': pd.date_range('2016-01-01', '2019-12-31')})
cdf = cumulative.calculate_daily_cumulative_values(
df, 'data', date_column_name='date', year_type='climate',
allow_incomplete_years=False)
df, 'data', date_column_name='date', year_type='climate')
assert cdf.shape == (365*3, 3)
assert cdf.columns.tolist() == \
['index_year', 'index_doy', 'cumulative']
Expand Down

0 comments on commit 91678d2

Please sign in to comment.