datetime does not work with non-constant pytz.timezone
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Mon, 21 Oct 2024 18:43:11 +0000 (19:43 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Mon, 21 Oct 2024 18:43:11 +0000 (19:43 +0100)
This has always been the case (and is explicitly warned about
in the pytz documentation), but became a test fail when
tzdata 2024b changed 'CET' and similar to aliases.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: no

Gbp-Pq: Name no_pytz_datetime.patch

pandas/tests/arrays/test_array.py

index 96263f498935b0d975b12c74b7cd98c6c4853670..007aed25d29e64fb3444d492cf2d82cd395868c2 100644 (file)
@@ -272,7 +272,8 @@ def test_array_copy():
     assert tm.shares_memory(a, b)
 
 
-cet = pytz.timezone("CET")
+cetfixed = pytz.timezone("Etc/GMT-1") # the wrong-looking sign is because Etc/* use posix convention, as described in the tzdata source
+cetwithdst = pytz.timezone("Europe/Brussels")
 
 
 @pytest.mark.parametrize(
@@ -313,11 +314,20 @@ cet = pytz.timezone("CET")
         ),
         (
             [
-                datetime.datetime(2000, 1, 1, tzinfo=cet),
-                datetime.datetime(2001, 1, 1, tzinfo=cet),
+                datetime.datetime(2000, 1, 1, tzinfo=cetfixed),
+                datetime.datetime(2001, 1, 1, tzinfo=cetfixed),
             ],
             DatetimeArray._from_sequence(
-                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cet, unit="ns")
+                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cetfixed, unit="ns")
+            ),
+        ),
+        (
+            [
+                cetwithdst.localize(datetime.datetime(2000, 1, 1)),
+                cetwithdst.localize(datetime.datetime(2001, 1, 1)),
+            ],
+            DatetimeArray._from_sequence(
+                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cetwithdst, unit="ns")
             ),
         ),
         # timedelta