From b3e3702727a254749c4ce917709db401abeb7b2d Mon Sep 17 00:00:00 2001 From: C1-BA-B1-F3 Date: Fri, 26 Jun 2026 06:16:19 +0800 Subject: [PATCH] fix: defer pd.to_datetime() calls in test parametrize to avoid nightly segfault Move pd.to_datetime() calls from module-level @pytest.mark.parametrize into the test function body. This avoids a segfault in pandas nightly caused by constructing datetime objects at module import time. Fixes #11402 --- xarray/tests/test_coding_times.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xarray/tests/test_coding_times.py b/xarray/tests/test_coding_times.py index e03f15a5119..c3eac3d7f00 100644 --- a/xarray/tests/test_coding_times.py +++ b/xarray/tests/test_coding_times.py @@ -538,20 +538,21 @@ def test_infer_datetime_units(freq, units) -> None: @pytest.mark.parametrize( - ["dates", "expected"], + ["date_strings", "expected"], [ ( - pd.to_datetime(["1900-01-01", "1900-01-02", "NaT"], unit="ns"), + ["1900-01-01", "1900-01-02", "NaT"], "days since 1900-01-01 00:00:00", ), ( - pd.to_datetime(["NaT", "1900-01-01"], unit="ns"), + ["NaT", "1900-01-01"], "days since 1900-01-01 00:00:00", ), - (pd.to_datetime(["NaT"], unit="ns"), "days since 1970-01-01 00:00:00"), + (["NaT"], "days since 1970-01-01 00:00:00"), ], ) -def test_infer_datetime_units_with_NaT(dates, expected) -> None: +def test_infer_datetime_units_with_NaT(date_strings, expected) -> None: + dates = pd.to_datetime(date_strings, unit="ns") assert expected == infer_datetime_units(dates)