Skip to content

Commit

Permalink
feat(python): Drop python 3.8 support (#18965)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Sep 27, 2024
1 parent 3342cc2 commit a0ec630
Show file tree
Hide file tree
Showing 103 changed files with 325 additions and 278 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.12']
python-version: ['3.9', '3.12']

steps:
- uses: actions/checkout@v4
Expand All @@ -63,4 +63,4 @@ jobs:
# Allow untyped calls for older Python versions
- name: Run mypy
working-directory: py-polars
run: mypy ${{ (matrix.python-version == '3.8') && '--allow-untyped-calls' || '' }}
run: mypy ${{ (matrix.python-version == '3.9') && '--allow-untyped-calls' || '' }}
2 changes: 1 addition & 1 deletion .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:
cancel-in-progress: true

env:
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.9'
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.11', '3.12']
python-version: ['3.9', '3.12']
include:
- os: windows-latest
python-version: '3.12'
Expand Down
2 changes: 1 addition & 1 deletion py-polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ libc = { workspace = true }
# Explicit dependency is needed to add bigidx in CI during release
polars = { workspace = true }
polars-python = { workspace = true, features = ["pymethods", "iejoin"] }
pyo3 = { workspace = true, features = ["abi3-py38", "chrono", "extension-module", "multiple-pymethods"] }
pyo3 = { workspace = true, features = ["abi3-py39", "chrono", "extension-module", "multiple-pymethods"] }

[build-dependencies]
built = { version = "0.7", features = ["chrono", "git2", "cargo-lock"], optional = true }
Expand Down
52 changes: 23 additions & 29 deletions py-polars/polars/_typing.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from __future__ import annotations

from collections.abc import Collection, Iterable, Mapping, Sequence
from typing import (
TYPE_CHECKING,
Any,
Collection,
Iterable,
List,
Literal,
Mapping,
Protocol,
Sequence,
Tuple,
Type,
TypedDict,
TypeVar,
Union,
Expand Down Expand Up @@ -55,37 +49,37 @@ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:

# Data types
PolarsDataType: TypeAlias = Union["DataTypeClass", "DataType"]
PolarsTemporalType: TypeAlias = Union[Type["TemporalType"], "TemporalType"]
PolarsIntegerType: TypeAlias = Union[Type["IntegerType"], "IntegerType"]
PolarsTemporalType: TypeAlias = Union[type["TemporalType"], "TemporalType"]
PolarsIntegerType: TypeAlias = Union[type["IntegerType"], "IntegerType"]
OneOrMoreDataTypes: TypeAlias = Union[PolarsDataType, Iterable[PolarsDataType]]
PythonDataType: TypeAlias = Union[
Type[int],
Type[float],
Type[bool],
Type[str],
Type["date"],
Type["time"],
Type["datetime"],
Type["timedelta"],
Type[List[Any]],
Type[Tuple[Any, ...]],
Type[bytes],
Type[object],
Type["Decimal"],
Type[None],
type[int],
type[float],
type[bool],
type[str],
type["date"],
type["time"],
type["datetime"],
type["timedelta"],
type[list[Any]],
type[tuple[Any, ...]],
type[bytes],
type[object],
type["Decimal"],
type[None],
]

SchemaDefinition: TypeAlias = Union[
Mapping[str, Union[PolarsDataType, PythonDataType]],
Sequence[Union[str, Tuple[str, Union[PolarsDataType, PythonDataType, None]]]],
Sequence[Union[str, tuple[str, Union[PolarsDataType, PythonDataType, None]]]],
]
SchemaDict: TypeAlias = Mapping[str, PolarsDataType]

NumericLiteral: TypeAlias = Union[int, float, "Decimal"]
TemporalLiteral: TypeAlias = Union["date", "time", "datetime", "timedelta"]
NonNestedLiteral: TypeAlias = Union[NumericLiteral, TemporalLiteral, str, bool, bytes]
# Python literal types (can convert into a `lit` expression)
PythonLiteral: TypeAlias = Union[NonNestedLiteral, List[Any]]
PythonLiteral: TypeAlias = Union[NonNestedLiteral, list[Any]]
# Inputs that can convert into a `col` expression
IntoExprColumn: TypeAlias = Union["Expr", "Series", str]
# Inputs that can convert into an expression
Expand Down Expand Up @@ -204,7 +198,7 @@ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:
# Excel IO
ColumnFormatDict: TypeAlias = Mapping[
# dict of colname(s) or selector(s) to format string or dict
Union[ColumnNameOrSelector, Tuple[ColumnNameOrSelector, ...]],
Union[ColumnNameOrSelector, tuple[ColumnNameOrSelector, ...]],
Union[str, Mapping[str, str]],
]
ConditionalFormatDict: TypeAlias = Mapping[
Expand All @@ -214,12 +208,12 @@ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:
]
ColumnTotalsDefinition: TypeAlias = Union[
# dict of colname(s) to str, a collection of str, or a boolean
Mapping[Union[ColumnNameOrSelector, Tuple[ColumnNameOrSelector]], str],
Mapping[Union[ColumnNameOrSelector, tuple[ColumnNameOrSelector]], str],
Sequence[str],
bool,
]
ColumnWidthsDefinition: TypeAlias = Union[
Mapping[ColumnNameOrSelector, Union[Tuple[str, ...], int]], int
Mapping[ColumnNameOrSelector, Union[tuple[str, ...], int]], int
]
RowTotalsDefinition: TypeAlias = Union[
# dict of colname to str(s), a collection of str, or a boolean
Expand All @@ -234,7 +228,7 @@ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:
# typevars for core polars types
PolarsType = TypeVar("PolarsType", "DataFrame", "LazyFrame", "Series", "Expr")
FrameType = TypeVar("FrameType", "DataFrame", "LazyFrame")
BufferInfo: TypeAlias = Tuple[int, int, int]
BufferInfo: TypeAlias = tuple[int, int, int]

# type alias for supported spreadsheet engines
ExcelSpreadsheetEngine: TypeAlias = Literal["xlsx2csv", "openpyxl", "calamine"]
Expand Down
4 changes: 3 additions & 1 deletion py-polars/polars/_utils/async_.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Awaitable, Generator, Generic, TypeVar
from collections.abc import Awaitable
from typing import TYPE_CHECKING, Any, Generic, TypeVar

from polars._utils.wrap import wrap_df
from polars.dependencies import _GEVENT_AVAILABLE

if TYPE_CHECKING:
from asyncio.futures import Future
from collections.abc import Generator

from polars.polars import PyDataFrame

Expand Down
8 changes: 3 additions & 5 deletions py-polars/polars/_utils/construction/dataframe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import contextlib
from collections.abc import Generator, Mapping
from datetime import date, datetime, time, timedelta
from functools import singledispatch
from itertools import islice, zip_longest
Expand All @@ -9,11 +10,6 @@
TYPE_CHECKING,
Any,
Callable,
Generator,
Iterable,
Mapping,
MutableMapping,
Sequence,
)

import polars._reexport as pl
Expand Down Expand Up @@ -63,6 +59,8 @@
from polars.polars import PyDataFrame

if TYPE_CHECKING:
from collections.abc import Iterable, MutableMapping, Sequence

from polars import DataFrame, Expr, Series
from polars._typing import (
Orientation,
Expand Down
7 changes: 3 additions & 4 deletions py-polars/polars/_utils/construction/series.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from __future__ import annotations

import contextlib
from collections.abc import Generator, Iterator
from datetime import date, datetime, time, timedelta
from itertools import islice
from typing import (
TYPE_CHECKING,
Any,
Callable,
Generator,
Iterable,
Iterator,
Sequence,
)

import polars._reexport as pl
Expand Down Expand Up @@ -65,6 +62,8 @@
from polars.polars import PySeries

if TYPE_CHECKING:
from collections.abc import Iterable, Sequence

from polars import DataFrame, Series
from polars._typing import PolarsDataType
from polars.dependencies import pandas as pd
Expand Down
4 changes: 3 additions & 1 deletion py-polars/polars/_utils/construction/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import sys
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Callable, Sequence, get_type_hints
from typing import TYPE_CHECKING, Any, Callable, get_type_hints

from polars.dependencies import _check_for_pydantic, pydantic

if TYPE_CHECKING:
from collections.abc import Sequence

import pandas as pd

PANDAS_SIMPLE_NUMPY_DTYPES = {
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/_utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Any,
Callable,
NoReturn,
Sequence,
no_type_check,
overload,
)
Expand All @@ -26,6 +25,7 @@
from polars.dependencies import _ZONEINFO_AVAILABLE, zoneinfo

if TYPE_CHECKING:
from collections.abc import Sequence
from datetime import date, tzinfo
from decimal import Decimal

Expand Down
5 changes: 3 additions & 2 deletions py-polars/polars/_utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations

import inspect
from collections.abc import Sequence
from functools import wraps
from typing import TYPE_CHECKING, Callable, Sequence, TypeVar
from typing import TYPE_CHECKING, Callable, TypeVar

from polars._utils.various import issue_warning

if TYPE_CHECKING:
import sys
from typing import Mapping
from collections.abc import Mapping

from polars._typing import Ambiguous

Expand Down
5 changes: 4 additions & 1 deletion py-polars/polars/_utils/getitem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterable, NoReturn, Sequence, overload
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, NoReturn, overload

import polars._reexport as pl
import polars.functions as F
Expand All @@ -22,6 +23,8 @@
from polars.meta.index_type import get_index_type

if TYPE_CHECKING:
from collections.abc import Iterable

from polars import DataFrame, Series
from polars._typing import (
MultiColSelector,
Expand Down
3 changes: 2 additions & 1 deletion py-polars/polars/_utils/parse/expr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import contextlib
from typing import TYPE_CHECKING, Any, Iterable
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any

import polars._reexport as pl
from polars import functions as F
Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/_utils/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
from pathlib import Path
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
ClassVar,
Iterator,
Literal,
NamedTuple,
Union,
Expand All @@ -29,6 +27,8 @@
from polars._utils.various import re_escape

if TYPE_CHECKING:
from collections.abc import Iterator
from collections.abc import Set as AbstractSet
from dis import Instruction

if sys.version_info >= (3, 10):
Expand Down
13 changes: 8 additions & 5 deletions py-polars/polars/_utils/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import re
import sys
import warnings
from collections.abc import MappingView, Sized
from collections.abc import (
Collection,
Generator,
Iterable,
MappingView,
Sequence,
Sized,
)
from enum import Enum
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Callable,
Collection,
Generator,
Iterable,
Literal,
Sequence,
TypeVar,
overload,
)
Expand Down
5 changes: 4 additions & 1 deletion py-polars/polars/convert/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import io
import itertools
import re
from typing import TYPE_CHECKING, Any, Iterable, Mapping, Sequence, overload
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, Any, overload

import polars._reexport as pl
from polars import functions as F
Expand All @@ -24,6 +25,8 @@
from polars.exceptions import NoDataError

if TYPE_CHECKING:
from collections.abc import Mapping

from polars import DataFrame, Series
from polars._typing import Orientation, SchemaDefinition, SchemaDict
from polars.dependencies import numpy as np
Expand Down
17 changes: 5 additions & 12 deletions py-polars/polars/convert/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@

import json
from collections import abc
from typing import TYPE_CHECKING, Any, Sequence
from typing import TYPE_CHECKING, Any

from polars._utils.unstable import unstable
from polars.dataframe import DataFrame
from polars.datatypes.constants import N_INFER_DEFAULT

if TYPE_CHECKING:
from polars.schema import Schema

import sys
from collections.abc import Sequence

if sys.version_info >= (3, 9):
from polars.schema import Schema

def _remove_prefix(text: str, prefix: str) -> str:
return text.removeprefix(prefix)
else:

def _remove_prefix(text: str, prefix: str) -> str:
if text.startswith(prefix):
return text[len(prefix) :]
return text
def _remove_prefix(text: str, prefix: str) -> str:
return text.removeprefix(prefix)


def _simple_json_normalize(
Expand Down
Loading

0 comments on commit a0ec630

Please sign in to comment.