From babf8ec4aaa6b0ad77266952d309aef0e427e5f0 Mon Sep 17 00:00:00 2001 From: zssherman Date: Tue, 30 Jun 2026 14:31:24 -0500 Subject: [PATCH] FIX: Update time units for new timedelta changes. --- act/qc/comparison_tests.py | 2 +- act/utils/data_utils.py | 5 +++-- tests/io/test_arm.py | 7 ++++--- tests/utils/test_datetime_utils.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/act/qc/comparison_tests.py b/act/qc/comparison_tests.py index 1436414649..80c5c1875a 100644 --- a/act/qc/comparison_tests.py +++ b/act/qc/comparison_tests.py @@ -86,7 +86,7 @@ def compare_time_series_trends( sum_diff = np.array([], dtype=float) time_diff = np.array([], dtype=np.int32) for tm_shift in range(-1 * time_shift, time_shift + int(time_step), int(time_step)): - time = self_da.time.values.astype('datetime64[s]') + tm_shift + time = self_da.time.values.astype('datetime64[s]') + np.timedelta64(int(tm_shift), 's') time = time.astype('datetime64[ns]') self_da_shifted = self_da.assign_coords(time=time) diff --git a/act/utils/data_utils.py b/act/utils/data_utils.py index 2cd3dbe9f8..ffd47b621e 100644 --- a/act/utils/data_utils.py +++ b/act/utils/data_utils.py @@ -475,8 +475,9 @@ def add_in_nan(time, data): else: # For 2D plots need to add a NaN right after and right before the data # to correctly mitigate streaking with pcolormesh. - time_added_1 = time[corr_i] + 1 # One time step after - time_added_2 = time[corr_i + 1] - 1 # One time step before + unit, _ = np.datetime_data(time.dtype) + time_added_1 = time[corr_i] + np.timedelta64(1, unit) # One time step after + time_added_2 = time[corr_i + 1] - np.timedelta64(1, unit) # One time step before time = np.insert(time, corr_i + 1, [time_added_1, time_added_2]) data = np.insert(data, corr_i + 1, np.nan, axis=0) data = np.insert(data, corr_i + 2, np.nan, axis=0) diff --git a/tests/io/test_arm.py b/tests/io/test_arm.py index 1fc9c85dfa..a21a299e23 100644 --- a/tests/io/test_arm.py +++ b/tests/io/test_arm.py @@ -2,6 +2,7 @@ from pathlib import Path import numpy as np +import pytest import act from act.tests import sample_files @@ -13,7 +14,7 @@ def test_read_arm_netcdf(): assert 'rh_mean' in ds.variables.keys() assert ds.attrs['_arm_standards_flag'] == (1 << 0) - with np.testing.assert_raises(OSError): + with pytest.raises(OSError): ds = act.io.arm.read_arm_netcdf([]) ds = act.io.arm.read_arm_netcdf([], return_None=True) @@ -154,12 +155,12 @@ def test_io_dod(): assert 'moment1' in ds assert len(ds['base_time'].values) == 1440 assert len(ds['drop_diameter'].values) == 50 - with np.testing.assert_warns(UserWarning): + with pytest.warns(UserWarning): ds2 = act.io.arm.create_ds_from_arm_dod('vdis.b1', dims, scalar_fill_dim='time') assert 'moment1' in ds2 assert len(ds2['base_time'].values) == 1440 assert len(ds2['drop_diameter'].values) == 50 - with np.testing.assert_raises(ValueError): + with pytest.raises(ValueError): ds = act.io.arm.create_ds_from_arm_dod('vdis.b1', {}, version='1.2') ds = act.io.arm.create_ds_from_arm_dod( sample_files.EXAMPLE_DOD, dims, version=1.2, scalar_fill_dim='time', local_file=True diff --git a/tests/utils/test_datetime_utils.py b/tests/utils/test_datetime_utils.py index 79d4b65055..b508aa9618 100644 --- a/tests/utils/test_datetime_utils.py +++ b/tests/utils/test_datetime_utils.py @@ -13,7 +13,7 @@ def test_dates_between(): start_string = datetime.strptime(start_date, '%Y%m%d').strftime('%Y-%m-%d') end_string = datetime.strptime(end_date, '%Y%m%d').strftime('%Y-%m-%d') answer = np.arange(start_string, end_string, dtype='datetime64[D]') - answer = np.append(answer, answer[-1] + 1) + answer = np.append(answer, answer[-1] + np.timedelta64(1, 'D')) answer = answer.astype('datetime64[s]').astype(int) answer = [datetime.fromtimestamp(ii, tz=timezone.utc).replace(tzinfo=None) for ii in answer]