Skip to content

Commit

Permalink
fix tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Dec 10, 2024
1 parent c07df41 commit 9653a01
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,33 +275,43 @@ def test_0d_time_data(self):
expected = np.datetime64("2000-01-01", "ns")
assert x[0].values == expected

dt64_data = pd.date_range("2000-01-01", periods=3)

@pytest.mark.filterwarnings("ignore:Converting non-default")
def test_datetime64_conversion(self):
times = pd.date_range("2000-01-01", periods=3)
for values in [
times,
times.values,
times.values.astype("datetime64[s]"),
times.to_pydatetime(),
]:
v = self.cls(["t"], values)
assert v.dtype == np.dtype("datetime64[ns]")
assert_array_equal(v.values, times.values)
assert v.values.dtype == np.dtype("datetime64[ns]")
@pytest.mark.parametrize(
"values, unit",
[
(dt64_data, "ns"),
(dt64_data.values, "ns"),
(dt64_data.values.astype("datetime64[s]"), "s"),
(dt64_data.to_pydatetime(), "ns"),
],
)
def test_datetime64_conversion(self, values, unit):
# todo: check, if this test is OK
v = self.cls(["t"], values)
assert v.dtype == np.dtype(f"datetime64[{unit}]")
assert_array_equal(v.values, self.dt64_data.values)
assert v.values.dtype == np.dtype(f"datetime64[{unit}]")

td64_data = pd.timedelta_range(start=0, periods=3)

@pytest.mark.filterwarnings("ignore:Converting non-default")
def test_timedelta64_conversion(self):
times = pd.timedelta_range(start=0, periods=3)
for values in [
times,
times.values,
times.values.astype("timedelta64[s]"),
times.to_pytimedelta(),
]:
v = self.cls(["t"], values)
assert v.dtype == np.dtype("timedelta64[ns]")
assert_array_equal(v.values, times.values)
assert v.values.dtype == np.dtype("timedelta64[ns]")
@pytest.mark.parametrize(
"values, unit",
[
(td64_data, "ns"),
(td64_data.values, "ns"),
(td64_data.values.astype("timedelta64[s]"), "s"),
(td64_data.to_pytimedelta(), "ns"),
],
)
def test_timedelta64_conversion(self, values, unit):
# todo: check, if this test is OK
v = self.cls(["t"], values)
assert v.dtype == np.dtype(f"timedelta64[{unit}]")
assert_array_equal(v.values, self.td64_data.values)
assert v.values.dtype == np.dtype(f"timedelta64[{unit}]")

def test_object_conversion(self):
data = np.arange(5).astype(str).astype(object)
Expand Down

0 comments on commit 9653a01

Please sign in to comment.