Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 27, 2024
1 parent 8929b52 commit bc9a5d2
Show file tree
Hide file tree
Showing 78 changed files with 214 additions and 214 deletions.
47 changes: 22 additions & 25 deletions py-polars/polars/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
from typing import (
TYPE_CHECKING,
Any,
List,
Literal,
Protocol,
Tuple,
Type,
TypedDict,
TypeVar,
Union,
Expand Down Expand Up @@ -52,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 @@ -201,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 @@ -211,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 @@ -231,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
3 changes: 2 additions & 1 deletion py-polars/polars/_utils/async_.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from collections.abc import Awaitable, Generator
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
4 changes: 3 additions & 1 deletion py-polars/polars/_utils/construction/dataframe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib
from collections.abc import Generator, Iterable, Mapping, MutableMapping, Sequence
from collections.abc import Generator, Mapping
from datetime import date, datetime, time, timedelta
from functools import singledispatch
from itertools import islice, zip_longest
Expand Down Expand Up @@ -59,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
4 changes: 3 additions & 1 deletion py-polars/polars/_utils/construction/series.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib
from collections.abc import Generator, Iterable, Iterator, Sequence
from collections.abc import Generator, Iterator
from datetime import date, datetime, time, timedelta
from itertools import islice
from typing import (
Expand Down Expand Up @@ -62,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
3 changes: 2 additions & 1 deletion py-polars/polars/_utils/construction/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

import sys
from collections.abc import Sequence
from functools import lru_cache
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
@@ -1,6 +1,5 @@
from __future__ import annotations

from collections.abc import Sequence
from datetime import datetime, time, timedelta, timezone
from decimal import Context
from functools import lru_cache
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
4 changes: 3 additions & 1 deletion py-polars/polars/_utils/getitem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

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

import polars._reexport as pl
Expand All @@ -23,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
4 changes: 2 additions & 2 deletions py-polars/polars/_utils/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import warnings
from bisect import bisect_left
from collections import defaultdict
from collections.abc import Iterator
from dis import get_instructions
from inspect import signature
from itertools import count, zip_longest
from pathlib import Path
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
ClassVar,
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
4 changes: 3 additions & 1 deletion py-polars/polars/convert/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io
import itertools
import re
from collections.abc import Iterable, Mapping, Sequence
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, Any, overload

import polars._reexport as pl
Expand All @@ -25,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
16 changes: 4 additions & 12 deletions py-polars/polars/convert/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@

import json
from collections import abc
from collections.abc import 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
2 changes: 1 addition & 1 deletion py-polars/polars/dataframe/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from __future__ import annotations

import os
from collections.abc import Iterable
from textwrap import dedent
from typing import TYPE_CHECKING

from polars.dependencies import html

if TYPE_CHECKING:
from collections.abc import Iterable
from types import TracebackType

from polars import DataFrame
Expand Down
13 changes: 8 additions & 5 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import random
from collections import defaultdict
from collections.abc import (
Collection,
Generator,
Iterable,
Iterator,
Mapping,
Sequence,
Sized,
)
Expand Down Expand Up @@ -117,6 +114,11 @@

if TYPE_CHECKING:
import sys
from collections.abc import (
Collection,
Iterator,
Mapping,
)
from datetime import timedelta
from io import IOBase
from typing import Literal
Expand Down Expand Up @@ -3975,8 +3977,9 @@ def unpack_table_name(name: str) -> tuple[str | None, str | None, str]:
else (connection, False)
)
with (
conn if can_close_conn else contextlib.nullcontext()
), conn.cursor() as cursor:
conn if can_close_conn else contextlib.nullcontext(),
conn.cursor() as cursor,
):
catalog, db_schema, unpacked_table_name = unpack_table_name(table_name)
n_rows: int
if adbc_version >= (0, 7):
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/dataframe/group_by.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from collections.abc import Iterable
from typing import TYPE_CHECKING, Callable

from polars import functions as F
Expand All @@ -9,6 +8,7 @@

if TYPE_CHECKING:
import sys
from collections.abc import Iterable
from datetime import timedelta

from polars import DataFrame
Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/dataframe/plotting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Dict, Union
from typing import TYPE_CHECKING, Callable, Union

from polars.dependencies import altair as alt

Expand All @@ -27,7 +27,7 @@
from typing_extensions import Unpack

Encoding: TypeAlias = Union[X, Y, Color, Order, Size, Tooltip]
Encodings: TypeAlias = Dict[str, Encoding]
Encodings: TypeAlias = dict[str, Encoding]


def _maybe_extract_shorthand(encoding: Encoding) -> Encoding:
Expand Down
4 changes: 3 additions & 1 deletion py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import contextlib
from collections import OrderedDict
from collections.abc import Iterable, Iterator, Mapping, Sequence
from collections.abc import Mapping
from datetime import timezone
from inspect import isclass
from typing import TYPE_CHECKING, Any
Expand All @@ -15,6 +15,8 @@
from polars.polars import dtype_str_repr as _dtype_str_repr

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

from polars import Series
from polars._typing import (
CategoricalOrdering,
Expand Down
3 changes: 2 additions & 1 deletion py-polars/polars/datatypes/constructor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import functools
from collections.abc import Sequence
from decimal import Decimal as PyDecimal
from typing import TYPE_CHECKING, Any, Callable

Expand All @@ -17,6 +16,8 @@
_DOCUMENTING = True

if TYPE_CHECKING:
from collections.abc import Sequence

from polars._typing import PolarsDataType

if not _DOCUMENTING:
Expand Down
Loading

0 comments on commit bc9a5d2

Please sign in to comment.