Skip to content

Commit 34a3ffe

Browse files
Merge pull request #155 from aodn/fix_time_index_py35
Fix for time index type issue that works in Python 3.5.2
2 parents 8f02f5f + b9ef058 commit 34a3ffe

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

aodntools/timeseries_products/hourly_timeseries.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,12 @@ def hourly_aggregator(files_to_aggregate, site_code, qcflags, input_dir='', outp
407407
'NOMINAL_DEPTH': get_nominal_depth(nc)},
408408
ignore_index=True)
409409

410-
# reindex in case TIME had out-of-range values before cleaning
411-
df_temp = nc_clean.reindex({'TIME': nc_clean.TIME.values}).to_dataframe()
410+
# If TIME had out-of-range values before cleaning, nc_clean would now have a CFTimeIndex, which
411+
# breaks the resampling further down. Here we reset it to a DatetimeIndex as suggested here:
412+
# https://stackoverflow.com/questions/55786995/converting-cftime-datetimejulian-to-datetime/55787899#55787899
413+
if isinstance(nc_clean.indexes['TIME'], xr.coding.cftimeindex.CFTimeIndex):
414+
nc_clean['TIME'] = nc_clean.indexes['TIME'].to_datetimeindex()
415+
df_temp = nc_clean.to_dataframe()
412416

413417
df_temp = df_temp[parameter_names]
414418

0 commit comments

Comments
 (0)