Skip to content

Commit cda2fe1

Browse files
committed
Fix update_time_bounds_from_file_names
1 parent 35648cc commit cda2fe1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

mpas_analysis/shared/analysis_task.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ def flush(self):
602602
pass
603603

604604

605-
def update_time_bounds_from_file_names(config, section, componentName):
605+
def update_time_bounds_from_file_names(config, section, componentName,
606+
allow_cache=True):
606607
"""
607608
Update the start and end years and dates for time series, climatologies or
608609
climate indices based on the years actually available in the list of files.
@@ -680,12 +681,16 @@ def update_time_bounds_from_file_names(config, section, componentName):
680681
endYear = years[lastIndex]
681682

682683
if startYear != requestedStartYear or endYear != requestedEndYear:
683-
print("Warning:"
684-
"{} start and/or end year different from requested\n"
685-
"requested: {:04d}-{:04d}\n"
686-
"actual: {:04d}-{:04d}\n".format(
687-
section, requestedStartYear, requestedEndYear, startYear,
688-
endYear))
684+
message = ("{} start and/or end year different from requested\n"
685+
"requested: {:04d}-{:04d}\n"
686+
"actual: {:04d}-{:04d}\n".format(
687+
section, requestedStartYear, requestedEndYear, startYear,
688+
endYear)
689+
)
690+
if allow_cache:
691+
print(f'Warning: {message}')
692+
else:
693+
raise ValueError(message)
689694

690695
startDate = '{:04d}-01-01_00:00:00'.format(startYear)
691696
config.set(section, 'startDate', startDate)

mpas_analysis/test/test_mpas_climatology_task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def test_update_climatology_bounds_and_create_symlinks(self):
168168
with self.assertRaisesRegex(ValueError,
169169
'climatology start and/or end year '
170170
'different from requested'):
171-
update_time_bounds_from_file_names(config, 'climatology', 'ocean')
171+
update_time_bounds_from_file_names(config, 'climatology', 'ocean',
172+
allow_cache=False)
172173

173174
def test_subtask_run_analysis(self):
174175
mpasClimatologyTask = self.setup_task()

0 commit comments

Comments
 (0)