Skip to content

Remove compat for Python lower than 3.9 #52935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ workflows:
only: /^v.*/
matrix:
parameters:
cibw-build: ["cp38-manylinux_aarch64", "cp39-manylinux_aarch64", "cp310-manylinux_aarch64", "cp311-manylinux_aarch64"]
cibw-build: ["cp39-manylinux_aarch64", "cp310-manylinux_aarch64", "cp311-manylinux_aarch64"]
2 changes: 0 additions & 2 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from pandas.compat._constants import (
IS64,
PY39,
PY310,
PY311,
PYPY,
Expand Down Expand Up @@ -161,7 +160,6 @@ def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]:
"pa_version_under9p0",
"pa_version_under11p0",
"IS64",
"PY39",
"PY310",
"PY311",
"PYPY",
Expand Down
2 changes: 0 additions & 2 deletions pandas/compat/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

IS64 = sys.maxsize > 2**32

PY39 = sys.version_info >= (3, 9)
PY310 = sys.version_info >= (3, 10)
PY311 = sys.version_info >= (3, 11)
PYPY = platform.python_implementation() == "PyPy"


__all__ = [
"IS64",
"PY39",
"PY310",
"PY311",
"PYPY",
Expand Down
28 changes: 12 additions & 16 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
Series,
Timedelta,
Timestamp,
compat,
)
import pandas._testing as tm
from pandas.core import ops
Expand All @@ -81,18 +80,12 @@
del pa
has_pyarrow = True

zoneinfo = None
if compat.PY39:
# Import "zoneinfo" could not be resolved (reportMissingImports)
import zoneinfo # type: ignore[assignment]
import zoneinfo

# Although zoneinfo can be imported in Py39, it is effectively
# "not available" without tzdata/IANA tz data.
# We will set zoneinfo to not found in this case
try:
zoneinfo.ZoneInfo("UTC") # type: ignore[attr-defined]
except zoneinfo.ZoneInfoNotFoundError: # type: ignore[attr-defined]
zoneinfo = None
try:
zoneinfo.ZoneInfo("UTC")
except zoneinfo.ZoneInfoNotFoundError:
zoneinfo = None # type: ignore[assignment]


# ----------------------------------------------------------------
Expand Down Expand Up @@ -1221,7 +1214,12 @@ def iris(datapath) -> DataFrame:
timezone(timedelta(hours=-1), name="foo"),
]
if zoneinfo is not None:
TIMEZONES.extend([zoneinfo.ZoneInfo("US/Pacific"), zoneinfo.ZoneInfo("UTC")])
TIMEZONES.extend(
[
zoneinfo.ZoneInfo("US/Pacific"), # type: ignore[list-item]
zoneinfo.ZoneInfo("UTC"), # type: ignore[list-item]
]
)
TIMEZONE_IDS = [repr(i) for i in TIMEZONES]


Expand Down Expand Up @@ -1964,9 +1962,7 @@ def using_copy_on_write() -> bool:

warsaws = ["Europe/Warsaw", "dateutil/Europe/Warsaw"]
if zoneinfo is not None:
warsaws.append(
zoneinfo.ZoneInfo("Europe/Warsaw") # pyright: ignore[reportGeneralTypeIssues]
)
warsaws.append(zoneinfo.ZoneInfo("Europe/Warsaw")) # type: ignore[arg-type]


@pytest.fixture(params=warsaws)
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import numpy as np

from pandas.compat import PY39
from pandas.errors import UndefinedVariableError

import pandas.core.common as com
Expand Down Expand Up @@ -208,9 +207,6 @@ def _filter_nodes(superclass, all_nodes=_all_nodes):
_keyword_nodes = _filter_nodes(ast.keyword)
_alias_nodes = _filter_nodes(ast.alias)

if not PY39:
_slice_nodes = _filter_nodes(ast.slice)


# nodes that we don't support directly but are needed for parsing
_hacked_nodes = frozenset(["Assign", "Module", "Expr"])
Expand Down
25 changes: 9 additions & 16 deletions pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
timedelta,
timezone,
)
import zoneinfo

import dateutil.tz
from dateutil.tz import tzutc
Expand All @@ -13,10 +14,7 @@
import pytz

from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
from pandas.compat import (
PY39,
PY310,
)
from pandas.compat import PY310
from pandas.errors import OutOfBoundsDatetime

from pandas import (
Expand All @@ -25,9 +23,6 @@
Timestamp,
)

if PY39:
import zoneinfo


class TestTimestampConstructors:
def test_construct_from_string_invalid_raises(self):
Expand Down Expand Up @@ -845,15 +840,13 @@ def test_timestamp_constructor_retain_fold(tz, fold):
assert result == expected


_tzs = ["dateutil/Europe/London"]
if PY39:
try:
_tzs = [
"dateutil/Europe/London",
zoneinfo.ZoneInfo("Europe/London"), # type: ignore[list-item]
]
except zoneinfo.ZoneInfoNotFoundError:
pass
try:
_tzs = [
"dateutil/Europe/London",
zoneinfo.ZoneInfo("Europe/London"),
]
except zoneinfo.ZoneInfoNotFoundError:
_tzs = ["dateutil/Europe/London"]


@pytest.mark.parametrize("tz", _tzs)
Expand Down