Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ def cftime_to_nptime(
f"standard calendar. Reason: {e}."
) from e
else:
dt = np.datetime64("NaT")
dt = np.datetime64("NaT", time_unit)
new.append(dt)
return np.asarray(new).reshape(times.shape)

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _possibly_convert_objects(values):
and values.dtype.kind == "O"
and Version(pd.__version__) >= Version("3.0.0dev0")
):
result.dtype = values.dtype
result = result.view(values.dtype)
return result


Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_seasons(self) -> None:
dates = xr.date_range(
start="2000/01/01", freq="ME", periods=12, use_cftime=False
)
dates = dates.append(pd.Index([np.datetime64("NaT")]))
dates = dates.append(pd.Index([np.datetime64("NaT", "us")]))
dates = xr.DataArray(dates)
seasons = xr.DataArray(
[
Expand Down
6 changes: 5 additions & 1 deletion xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,11 @@ def test_roundtrip_datetime64_nanosecond_precision(
) -> None:
# test for GH7817
time = np.datetime64(timestr, format)
times = [np.datetime64("1970-01-01T00:00:00", format), np.datetime64("NaT"), time]
times = [
np.datetime64("1970-01-01T00:00:00", format),
np.datetime64("NaT", format),
time,
]

if use_encoding:
encoding = dict(dtype=dtype, _FillValue=fill_value)
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def test_chunk_by_frequency(self, freq: str, calendar: str, add_gap: bool) -> No
).to_numpy(copy=True)
if add_gap:
# introduce an empty bin
time[31 : 31 + ΔN] = np.datetime64("NaT")
time[31 : 31 + ΔN] = np.datetime64("NaT", "us")
time = time[~np.isnat(time)]
else:
time = time[:N]
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ def test_argmin_max_error():
["array", "expected"],
[
(
np.array([np.datetime64("2000-01-01"), np.datetime64("NaT")]),
np.array([np.datetime64("2000-01-01"), np.datetime64("NaT", "D")]),
np.array([False, True]),
),
(
np.array([np.timedelta64(1, "h"), np.timedelta64("NaT")]),
np.array([np.timedelta64(1, "h"), np.timedelta64("NaT", "h")]),
np.array([False, True]),
),
(
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def test_groupby_drops_nans(shuffle: bool, chunk: Literal[False] | dict) -> None
[
np.datetime64("2001-01-01"),
np.datetime64("2001-01-01"),
np.datetime64("NaT"),
np.datetime64("NaT", "D"),
],
)
expected5 = xr.DataArray(3, [("t", [np.datetime64("2001-01-01")])])
Expand Down Expand Up @@ -2018,7 +2018,7 @@ def test_resample_first_last(self, use_cftime) -> None:
# missing periods, GH10169
actual = array.isel(time=[0, 1, 2, 3, 8, 9]).resample(time="1D").last()
expected = DataArray(
np.array([times[3], np.datetime64("NaT"), times[9]]),
np.array([times[3], np.datetime64("NaT", "us"), times[9]]),
dims="time",
coords={"time": times[::4]},
name="time",
Expand Down Expand Up @@ -3836,7 +3836,7 @@ def test_mean_datetime_edge_cases():
# Test with NaT values
dates_with_nat = pd.date_range("2021-01-01", periods=4, freq="D")
dates_with_nat_array = dates_with_nat.values.copy()
dates_with_nat_array[1] = np.datetime64("NaT")
dates_with_nat_array[1] = np.datetime64("NaT", "us")

ds = xr.Dataset(
{
Expand Down
Loading