Skip to content

Commit

Permalink
Merge pull request #310 from MarcoGorelli/fixup-testse
Browse files Browse the repository at this point in the history
Fixup TestUISeriesConvertTimeUnit tests;  passes CI
  • Loading branch information
CommonClimate authored Jan 31, 2023
2 parents 51075ed + 83b6911 commit 54a1acb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pyleoclim/tests/test_core_Series.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ def test_filter_t1(self, method):
val_diff = ts_bp.value - ts2.value
assert np.mean(val_diff**2) < 0.1

@pytest.mark.xfail # wait for Marco to fix the "DateParseError: day is out of range for month: 0, at position 0" error
class TestUISeriesConvertTimeUnit:
'''Tests for Series.convert_time_unit'''

Expand All @@ -961,7 +960,7 @@ def test_convert_time_unit_t0(self,keep_log):
def test_convert_time_unit_t1(self):
ts = gen_ts(nt=550, alpha=1.0)
ts.time_unit = 'nonsense'
with pytest.raises(ValueError):
with pytest.warns(UserWarning, match=r'Time unit "nonsense" unknown; triggering defaults'):
ts.convert_time_unit('yr BP')

class TestUISeriesFillNA:
Expand Down
4 changes: 3 additions & 1 deletion pyleoclim/utils/tsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def convert_datetime_index_to_time(datetime_index, time_unit, time_name):
raise ValueError('The provided index is not a proper DatetimeIndex object')
else:
year_diff = (datetime_index.year - int(datum))
seconds_diff = (datetime_index.to_numpy() - datetime_index.year.astype(str).astype('datetime64[s]').to_numpy()).astype('int')
numpy_datetime_index = datetime_index.to_numpy()
years_floor = numpy_datetime_index.astype('datetime64[Y]').astype('datetime64[s]')
seconds_diff = (numpy_datetime_index - years_floor).astype('int')
diff = year_diff + seconds_diff / SECONDS_PER_YEAR
time = multiplier * diff / 10**exponent

Expand Down

0 comments on commit 54a1acb

Please sign in to comment.