Skip to content

Commit

Permalink
Fixed bug with time unit in basetime (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
pstradio authored Oct 25, 2022
1 parent 32dbc92 commit b3495d5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pytesmo/validation_framework/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,9 @@ def __init__(self,

self.drop_original = drop_original

def convert_generic(self, time_arr: np.array) -> np.array:
def convert_generic(self, time_arr: np.array, units: str = 'D') -> np.array:
"""Convert the generic time field to np.datetime[64] dtype"""
time_delta = time_arr.astype(int).astype('timedelta64[D]')
time_delta = time_arr.astype(int).astype(f'timedelta64[{units}]')
time_date = np.full(time_delta.shape,
self.base_time_reference) + time_delta

Expand Down Expand Up @@ -650,7 +650,7 @@ def _adapt(self, data: DataFrame) -> DataFrame:
return original

if self.base_time_reference is not None:
base_time_values = self.convert_generic(base_time_values)
base_time_values = self.convert_generic(base_time_values, self.base_time_units)

# If no offset is specified
if self.time_offset_fields is None:
Expand All @@ -671,4 +671,7 @@ def _adapt(self, data: DataFrame) -> DataFrame:
if self.base_time_field in data.columns:
data.drop(columns=[self.base_time_field], inplace=True)

# Remove NaNs from index, if present
data = data.loc[data.index.dropna()]

return data

0 comments on commit b3495d5

Please sign in to comment.