From 7482f0fb36bef35655e67c637c56c162b08ce944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BRIOL?= Date: Thu, 13 Jun 2024 22:34:45 +0200 Subject: [PATCH] Refactor numpy datetime64 representation in test_period.py --- src/pyinterp/tests/test_period.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pyinterp/tests/test_period.py b/src/pyinterp/tests/test_period.py index 409473bc..58ff9340 100644 --- a/src/pyinterp/tests/test_period.py +++ b/src/pyinterp/tests/test_period.py @@ -45,8 +45,14 @@ def test_interface(): assert not p1.is_null() assert str(p1) == '[1970-01-02, 1970-01-11)' - assert repr(p1) == ("Period(begin=numpy.datetime64('1970-01-02'), " - "end=numpy.datetime64('1970-01-10'), within=True)") + # With numpy 2.0.0rc1, the representation of a datetime64 is different + # from the one of numpy 1.21.2: "numpy" becomes "np". + if numpy.version.version >= '2.0.0': + assert repr(p1) == ("Period(begin=np.datetime64('1970-01-02'), " + "end=np.datetime64('1970-01-10'), within=True)") + else: + assert repr(p1) == ("Period(begin=numpy.datetime64('1970-01-02'), " + "end=numpy.datetime64('1970-01-10'), within=True)") assert pickle.loads(pickle.dumps(p1)) == p1