| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + Timezone strings are now parsed using `~zoneinfo.ZoneInfo` | ||
| 2 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3 | + | ||
| 4 | + Timezone strings are now parsed using `~zoneinfo.ZoneInfo` rather than | ||
| 5 | + `~dateutil.tz.gettz`. This change affects the following methods: | ||
| 6 | + | ||
| 7 | + - `matplotlib.axis.Axis.axis_date` | ||
| 8 | + - `matplotlib.dates.num2date` | ||
| 9 | + - `matplotlib.dates.DateFormatter` | ||
| 10 | + - `matplotlib.dates.DateLocator` and subclasses | ||
| 11 | + | ||
| 12 | + Timezone identifiers must be valid IANA time zone keys (for example, | ||
| 13 | + ``"America/New_York"``). Abbreviations (``"EST"``), POSIX strings | ||
| 14 | + (``"EST5EDT"``), and invalid time zone keys (``"Invalid/Zone"``) will | ||
| 15 | + now raise a `~zoneinfo.ZoneInfoNotFoundError`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2506,14 +2506,15 @@ def axis_date(self, tz=None): | |||
| 2506 | 2506 | Parameters | |
| 2507 | 2507 | ---------- | |
| 2508 | 2508 | tz : str or `datetime.tzinfo`, default: :rc:`timezone` | |
| 2509 | - The timezone used to create date labels. | ||
| 2509 | + The timezone used to create date labels. If a string, *tz* is passed to | ||
| 2510 | + `~zoneinfo.ZoneInfo`. | ||
| 2510 | 2511 | """ | |
| 2511 | 2512 | # By providing a sample datetime instance with the desired timezone, | |
| 2512 | 2513 | # the registered converter can be selected, and the "units" attribute, | |
| 2513 | 2514 | # which is the timezone, can be set. | |
| 2514 | 2515 | if isinstance(tz, str): | |
| 2515 | - import dateutil.tz | ||
| 2516 | - tz = dateutil.tz.gettz(tz) | ||
| 2516 | + import zoneinfo | ||
| 2517 | + tz = zoneinfo.ZoneInfo(tz) | ||
| 2517 | 2518 | self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz)) | |
| 2518 | 2519 | ||
| 2519 | 2520 | def get_tick_space(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | """ | |
| 2 | 2 | Matplotlib provides sophisticated date plotting capabilities, standing on the | |
| 3 | - shoulders of python :mod:`datetime` and the add-on module dateutil_. | ||
| 3 | + shoulders of python :mod:`datetime`, :mod:`zoneinfo`, and the add-on module dateutil_. | ||
| 4 | 4 | ||
| 5 | 5 | By default, Matplotlib uses the units machinery described in | |
| 6 | 6 | `~matplotlib.units` to convert `datetime.datetime`, and `numpy.datetime64` | |
@@ -87,7 +87,7 @@ | |||
| 87 | 87 | string. If you want to use a different timezone, pass the *tz* keyword | |
| 88 | 88 | argument of `num2date` to any date tick locators or formatters you create. This | |
| 89 | 89 | can be either a `datetime.tzinfo` instance or a string with the timezone name | |
| 90 | - that can be parsed by `~dateutil.tz.gettz`. | ||
| 90 | + that can be parsed by `~zoneinfo.ZoneInfo`. | ||
| 91 | 91 | ||
| 92 | 92 | A wide range of specific and general purpose date tick locators and | |
| 93 | 93 | formatters are provided in this module. See | |
@@ -177,13 +177,13 @@ | |||
| 177 | 177 | import functools | |
| 178 | 178 | import logging | |
| 179 | 179 | import re | |
| 180 | + import zoneinfo | ||
| 180 | 181 | ||
| 181 | 182 | from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, | |
| 182 | 183 | MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, | |
| 183 | 184 | SECONDLY) | |
| 184 | 185 | from dateutil.relativedelta import relativedelta | |
| 185 | 186 | import dateutil.parser | |
| 186 | - import dateutil.tz | ||
| 187 | 187 | import numpy as np | |
| 188 | 188 | ||
| 189 | 189 | import matplotlib as mpl | |
@@ -214,10 +214,10 @@ def _get_tzinfo(tz=None): | |||
| 214 | 214 | if tz == 'UTC': | |
| 215 | 215 | return UTC | |
| 216 | 216 | if isinstance(tz, str): | |
| 217 | - tzinfo = dateutil.tz.gettz(tz) | ||
| 217 | + tzinfo = zoneinfo.ZoneInfo(tz) | ||
| 218 | 218 | if tzinfo is None: | |
| 219 | 219 | raise ValueError(f"{tz} is not a valid timezone as parsed by" | |
| 220 | - " dateutil.tz.gettz.") | ||
| 220 | + " zoneinfo.ZoneInfo.") | ||
| 221 | 221 | return tzinfo | |
| 222 | 222 | if isinstance(tz, datetime.tzinfo): | |
| 223 | 223 | return tz | |
@@ -352,7 +352,7 @@ def _from_ordinalf(x, tz=None): | |||
| 352 | 352 | dt = dt.tolist() | |
| 353 | 353 | ||
| 354 | 354 | # datetime64 is always UTC: | |
| 355 | - dt = dt.replace(tzinfo=dateutil.tz.gettz('UTC')) | ||
| 355 | + dt = dt.replace(tzinfo=datetime.timezone.utc) | ||
| 356 | 356 | # but maybe we are working in a different timezone so move. | |
| 357 | 357 | dt = dt.astimezone(tz) | |
| 358 | 358 | # fix round off errors | |
@@ -463,7 +463,7 @@ def num2date(x, tz=None): | |||
| 463 | 463 | since the epoch. See `.get_epoch` for the | |
| 464 | 464 | epoch, which can be changed by :rc:`date.epoch` or `.set_epoch`. | |
| 465 | 465 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 466 | - Timezone of *x*. If a string, *tz* is passed to `dateutil.tz`. | ||
| 466 | + Timezone of *x*. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 467 | 467 | ||
| 468 | 468 | Returns | |
| 469 | 469 | ------- | |
@@ -575,7 +575,7 @@ def __init__(self, fmt, tz=None, *, usetex=None): | |||
| 575 | 575 | fmt : str | |
| 576 | 576 | `~datetime.datetime.strftime` format string | |
| 577 | 577 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 578 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 578 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 579 | 579 | usetex : bool, default: :rc:`text.usetex` | |
| 580 | 580 | To enable/disable the use of TeX's math mode for rendering the | |
| 581 | 581 | results of the formatter. | |
@@ -888,7 +888,7 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d', *, | |||
| 888 | 888 | Locator that this axis is using. | |
| 889 | 889 | ||
| 890 | 890 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 891 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 891 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 892 | 892 | ||
| 893 | 893 | defaultfmt : str | |
| 894 | 894 | The default format to use if none of the values in ``self.scaled`` | |
@@ -1075,7 +1075,7 @@ def __init__(self, tz=None): | |||
| 1075 | 1075 | Parameters | |
| 1076 | 1076 | ---------- | |
| 1077 | 1077 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1078 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1078 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1079 | 1079 | """ | |
| 1080 | 1080 | self.tz = _get_tzinfo(tz) | |
| 1081 | 1081 | ||
@@ -1086,7 +1086,7 @@ def set_tzinfo(self, tz): | |||
| 1086 | 1086 | Parameters | |
| 1087 | 1087 | ---------- | |
| 1088 | 1088 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1089 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1089 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1090 | 1090 | """ | |
| 1091 | 1091 | self.tz = _get_tzinfo(tz) | |
| 1092 | 1092 | ||
@@ -1259,7 +1259,7 @@ def __init__(self, tz=None, minticks=5, maxticks=None, | |||
| 1259 | 1259 | Parameters | |
| 1260 | 1260 | ---------- | |
| 1261 | 1261 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1262 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1262 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1263 | 1263 | minticks : int | |
| 1264 | 1264 | The minimum number of ticks desired; controls whether ticks occur | |
| 1265 | 1265 | yearly, monthly, etc. | |
@@ -1470,7 +1470,7 @@ def __init__(self, base=1, month=1, day=1, tz=None): | |||
| 1470 | 1470 | day : int, default: 1 | |
| 1471 | 1471 | The day on which to place the ticks. | |
| 1472 | 1472 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1473 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1473 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1474 | 1474 | """ | |
| 1475 | 1475 | rule = rrulewrapper(YEARLY, interval=base, bymonth=month, | |
| 1476 | 1476 | bymonthday=day, **self.hms0d) | |
@@ -1513,7 +1513,7 @@ def __init__(self, bymonth=None, bymonthday=1, interval=1, tz=None): | |||
| 1513 | 1513 | The interval between each iteration. For example, if | |
| 1514 | 1514 | ``interval=2``, mark every second occurrence. | |
| 1515 | 1515 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1516 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1516 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1517 | 1517 | """ | |
| 1518 | 1518 | if bymonth is None: | |
| 1519 | 1519 | bymonth = range(1, 13) | |
@@ -1545,7 +1545,7 @@ def __init__(self, byweekday=1, interval=1, tz=None): | |||
| 1545 | 1545 | The interval between each iteration. For example, if | |
| 1546 | 1546 | ``interval=2``, mark every second occurrence. | |
| 1547 | 1547 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1548 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1548 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1549 | 1549 | """ | |
| 1550 | 1550 | rule = rrulewrapper(DAILY, byweekday=byweekday, | |
| 1551 | 1551 | interval=interval, **self.hms0d) | |
@@ -1568,7 +1568,7 @@ def __init__(self, bymonthday=None, interval=1, tz=None): | |||
| 1568 | 1568 | The interval between each iteration. For example, if | |
| 1569 | 1569 | ``interval=2``, mark every second occurrence. | |
| 1570 | 1570 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1571 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1571 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1572 | 1572 | """ | |
| 1573 | 1573 | if interval != int(interval) or interval < 1: | |
| 1574 | 1574 | raise ValueError("interval must be an integer greater than 0") | |
@@ -1595,7 +1595,7 @@ def __init__(self, byhour=None, interval=1, tz=None): | |||
| 1595 | 1595 | The interval between each iteration. For example, if | |
| 1596 | 1596 | ``interval=2``, mark every second occurrence. | |
| 1597 | 1597 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1598 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1598 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1599 | 1599 | """ | |
| 1600 | 1600 | if byhour is None: | |
| 1601 | 1601 | byhour = range(24) | |
@@ -1620,7 +1620,7 @@ def __init__(self, byminute=None, interval=1, tz=None): | |||
| 1620 | 1620 | The interval between each iteration. For example, if | |
| 1621 | 1621 | ``interval=2``, mark every second occurrence. | |
| 1622 | 1622 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1623 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1623 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1624 | 1624 | """ | |
| 1625 | 1625 | if byminute is None: | |
| 1626 | 1626 | byminute = range(60) | |
@@ -1645,7 +1645,7 @@ def __init__(self, bysecond=None, interval=1, tz=None): | |||
| 1645 | 1645 | The interval between each iteration. For example, if | |
| 1646 | 1646 | ``interval=2``, mark every second occurrence. | |
| 1647 | 1647 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1648 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1648 | + Ticks timezone. If a string, *tz* is passed to `~zoneinfo.ZoneInfo`. | ||
| 1649 | 1649 | """ | |
| 1650 | 1650 | if bysecond is None: | |
| 1651 | 1651 | bysecond = range(60) | |
@@ -1684,7 +1684,7 @@ def __init__(self, interval=1, tz=None): | |||
| 1684 | 1684 | The interval between each iteration. For example, if | |
| 1685 | 1685 | ``interval=2``, mark every second occurrence. | |
| 1686 | 1686 | tz : str or `~datetime.tzinfo`, default: :rc:`timezone` | |
| 1687 | - Ticks timezone. If a string, *tz* is passed to `dateutil.tz`. | ||
| 1687 | + Ticks timezone. If a string, *tz* is passed to `ZoneInfo`. | ||
| 1688 | 1688 | """ | |
| 1689 | 1689 | super().__init__(tz=tz) | |
| 1690 | 1690 | self._interval = interval | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,8 @@ | |||
| 1 | 1 | import datetime | |
| 2 | + import functools | ||
| 3 | + import zoneinfo | ||
| 2 | 4 | ||
| 3 | - import dateutil.tz | ||
| 4 | 5 | import dateutil.rrule | |
| 5 | - import functools | ||
| 6 | 6 | import numpy as np | |
| 7 | 7 | import pytest | |
| 8 | 8 | ||
@@ -943,7 +943,7 @@ def _create_auto_date_locator(date1, date2, tz): | |||
| 943 | 943 | ] | |
| 944 | 944 | ) | |
| 945 | 945 | ||
| 946 | - tz = dateutil.tz.gettz('Canada/Pacific') | ||
| 946 | + tz = zoneinfo.ZoneInfo('Canada/Pacific') | ||
| 947 | 947 | d1 = datetime.datetime(1997, 1, 1, tzinfo=tz) | |
| 948 | 948 | for t_delta, expected in results: | |
| 949 | 949 | with rc_context({'_internal.classic_mode': False}): | |
@@ -969,7 +969,7 @@ def test_date_inverted_limit(): | |||
| 969 | 969 | def _test_date2num_dst(date_range, tz_convert): | |
| 970 | 970 | # Timezones | |
| 971 | 971 | ||
| 972 | - BRUSSELS = dateutil.tz.gettz('Europe/Brussels') | ||
| 972 | + BRUSSELS = zoneinfo.ZoneInfo('Europe/Brussels') | ||
| 973 | 973 | UTC = mdates.UTC | |
| 974 | 974 | ||
| 975 | 975 | # Create a list of timezone-aware datetime objects in UTC | |
@@ -1072,8 +1072,8 @@ def _test_rrulewrapper(attach_tz, get_tz): | |||
| 1072 | 1072 | rule = mdates.rrulewrapper(freq=dateutil.rrule.DAILY, dtstart=dtstart) | |
| 1073 | 1073 | ||
| 1074 | 1074 | act = rule.between(dtstart, dtend) | |
| 1075 | - exp = [datetime.datetime(2017, 4, 1, 13, tzinfo=dateutil.tz.tzutc()), | ||
| 1076 | - datetime.datetime(2017, 4, 2, 14, tzinfo=dateutil.tz.tzutc())] | ||
| 1075 | + exp = [datetime.datetime(2017, 4, 1, 13, tzinfo=datetime.timezone.utc), | ||
| 1076 | + datetime.datetime(2017, 4, 2, 14, tzinfo=datetime.timezone.utc)] | ||
| 1077 | 1077 | ||
| 1078 | 1078 | assert act == exp | |
| 1079 | 1079 | ||
@@ -1082,9 +1082,9 @@ def test_rrulewrapper(): | |||
| 1082 | 1082 | def attach_tz(dt, zi): | |
| 1083 | 1083 | return dt.replace(tzinfo=zi) | |
| 1084 | 1084 | ||
| 1085 | - _test_rrulewrapper(attach_tz, dateutil.tz.gettz) | ||
| 1085 | + _test_rrulewrapper(attach_tz, zoneinfo.ZoneInfo) | ||
| 1086 | 1086 | ||
| 1087 | - SYD = dateutil.tz.gettz('Australia/Sydney') | ||
| 1087 | + SYD = zoneinfo.ZoneInfo('Australia/Sydney') | ||
| 1088 | 1088 | dtstart = datetime.datetime(2017, 4, 1, 0) | |
| 1089 | 1089 | dtend = datetime.datetime(2017, 4, 4, 0) | |
| 1090 | 1090 | rule = mdates.rrulewrapper(freq=dateutil.rrule.DAILY, dtstart=dtstart, | |
@@ -1316,7 +1316,7 @@ def test_DateLocator(): | |||
| 1316 | 1316 | # Check default is UTC | |
| 1317 | 1317 | assert locator.tz == mdates.UTC | |
| 1318 | 1318 | tz_str = 'Iceland' | |
| 1319 | - iceland_tz = dateutil.tz.gettz(tz_str) | ||
| 1319 | + iceland_tz = zoneinfo.ZoneInfo(tz_str) | ||
| 1320 | 1320 | # Check not Iceland | |
| 1321 | 1321 | assert locator.tz != iceland_tz | |
| 1322 | 1322 | # Set it to Iceland | |
@@ -1339,7 +1339,8 @@ def test_DateLocator(): | |||
| 1339 | 1339 | assert locator.tz == iceland_tz | |
| 1340 | 1340 | ||
| 1341 | 1341 | # Test invalid tz values | |
| 1342 | - with pytest.raises(ValueError, match="Aiceland is not a valid timezone"): | ||
| 1342 | + with pytest.raises(zoneinfo.ZoneInfoNotFoundError, | ||
| 1343 | + match="No time zone found with key Aiceland"): | ||
| 1343 | 1344 | mdates.DateLocator(tz="Aiceland") | |
| 1344 | 1345 | with pytest.raises(TypeError, | |
| 1345 | 1346 | match="tz must be string or tzinfo subclass."): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments