Skip to content

Commit

Permalink
refactor: replace deprecated classes of type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman authored and jcrist committed Aug 14, 2023
1 parent ec870a2 commit 25946f9
Show file tree
Hide file tree
Showing 86 changed files with 283 additions and 182 deletions.
5 changes: 4 additions & 1 deletion ci/make_geography_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import datetime
import tempfile
from pathlib import Path
from typing import Any, Mapping
from typing import TYPE_CHECKING, Any

import requests
import sqlalchemy as sa
import toolz

if TYPE_CHECKING:
from collections.abc import Mapping

SCHEMAS = {
"countries": [
("iso_alpha2", sa.TEXT),
Expand Down
4 changes: 2 additions & 2 deletions docs/backends/app/backend_info_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import tempfile
from pathlib import Path
from typing import List, Optional
from typing import Optional

import pandas as pd
import requests
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_all_operation_categories():


@st.cache_data(ttl=ONE_HOUR_IN_SECONDS)
def get_backend_names(categories: Optional[List[str]] = None):
def get_backend_names(categories: Optional[list[str]] = None):
backend_expr = backend_info_table.mutate(category=_.categories.unnest())
if categories:
backend_expr = backend_expr.filter(_.category.isin(categories))
Expand Down
7 changes: 2 additions & 5 deletions ibis/backends/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
Any,
Callable,
ClassVar,
Iterable,
Iterator,
Mapping,
MutableMapping,
)

import ibis
Expand All @@ -28,6 +24,7 @@
from ibis.common.caching import RefCountedCache

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
from pathlib import Path

import pandas as pd
Expand Down Expand Up @@ -1109,7 +1106,7 @@ def _transpile_sql(self, query: str, *, dialect: str | None = None) -> str:
return query


@functools.lru_cache(maxsize=None)
@functools.cache
def _get_backend_names() -> frozenset[str]:
"""Return the set of known backend names.
Expand Down
6 changes: 4 additions & 2 deletions ibis/backends/base/df/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
from __future__ import annotations

from collections import namedtuple
from typing import TYPE_CHECKING, Any, Iterable, Tuple
from typing import TYPE_CHECKING, Any

import pandas as pd

from ibis.backends.base.df.timecontext import TimeContextRelation, compare_timecontext

if TYPE_CHECKING:
from collections.abc import Iterable

from ibis.expr.operations import Node

TimeContext = Tuple[pd.Timestamp, pd.Timestamp]
TimeContext = tuple[pd.Timestamp, pd.Timestamp]

ScopeItem = namedtuple("ScopeItem", ["timecontext", "value"])

Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/base/df/timecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@

import enum
import functools
from typing import TYPE_CHECKING, Any, Tuple
from typing import TYPE_CHECKING, Any

import pandas as pd

import ibis.common.exceptions as com
import ibis.expr.operations as ops
from ibis import config

TimeContext = Tuple[pd.Timestamp, pd.Timestamp]
TimeContext = tuple[pd.Timestamp, pd.Timestamp]


if TYPE_CHECKING:
Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/base/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import contextlib
import os
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import TYPE_CHECKING, Any

import toolz

Expand All @@ -17,6 +17,8 @@
from ibis.backends.base.sql.compiler import Compiler

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

import pandas as pd
import pyarrow as pa

Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/base/sql/alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import getpass
import warnings
from operator import methodcaller
from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import TYPE_CHECKING, Any

import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
Expand Down Expand Up @@ -41,6 +41,8 @@
from ibis.formats.pandas import PandasData

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

import pandas as pd
import pyarrow as pa

Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/base/sql/alchemy/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Mapping
from typing import TYPE_CHECKING

import sqlalchemy as sa
import sqlalchemy.types as sat
Expand All @@ -12,6 +12,9 @@
from ibis.common.collections import FrozenDict
from ibis.formats import TypeMapper

if TYPE_CHECKING:
from collections.abc import Mapping

if geospatial_supported:
import geoalchemy2 as ga

Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/base/sql/compiler/query_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from io import StringIO
from typing import Iterable
from typing import TYPE_CHECKING

import sqlglot as sg
import toolz
Expand All @@ -17,6 +17,9 @@
from ibis.common.grounds import Comparable
from ibis.config import options

if TYPE_CHECKING:
from collections.abc import Iterable


class TableSetFormatter:
_join_names = {
Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/base/sql/compiler/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import contextlib
import itertools
from typing import Callable, Iterable, Iterator
from typing import TYPE_CHECKING, Callable

import ibis
import ibis.common.exceptions as com
import ibis.expr.operations as ops
from ibis.backends.base.sql.registry import operation_registry, quote_identifier

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator


class QueryContext:
"""Records bits of information used during ibis AST to SQL translation.
Expand Down
13 changes: 7 additions & 6 deletions ibis/backends/base/sql/registry/geospatial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Iterable, List, TypeVar
from collections.abc import Iterable
from typing import TYPE_CHECKING, TypeVar

import ibis.expr.datatypes as dt
from ibis.common import exceptions as ex
Expand All @@ -13,12 +14,12 @@
NumberType = TypeVar("NumberType", int, float)
# Geometry primitives (2D)
PointType = Iterable[NumberType]
LineStringType = List[PointType]
PolygonType = List[LineStringType]
LineStringType = list[PointType]
PolygonType = list[LineStringType]
# Multipart geometries (2D)
MultiPointType = List[PointType]
MultiLineStringType = List[LineStringType]
MultiPolygonType = List[PolygonType]
MultiPointType = list[PointType]
MultiLineStringType = list[LineStringType]
MultiPolygonType = list[PolygonType]


def _format_point_value(value: PointType) -> str:
Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import contextlib
import warnings
from typing import TYPE_CHECKING, Any, Callable, Iterable, Mapping
from typing import TYPE_CHECKING, Any, Callable
from urllib.parse import parse_qs, urlparse

import google.auth.credentials
Expand Down Expand Up @@ -35,6 +35,8 @@
from ibis.backends.bigquery.udf import udf # noqa: F401

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

import pyarrow as pa
from google.cloud.bigquery.table import RowIterator

Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/bigquery/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import functools
import io
import os
from typing import TYPE_CHECKING, Any, Mapping
from typing import TYPE_CHECKING, Any

import google.api_core.exceptions as gexc
import google.auth
Expand All @@ -22,6 +22,8 @@
from ibis.backends.tests.data import json_types, non_null_array_types, struct_types, win

if TYPE_CHECKING:
from collections.abc import Mapping

import ibis.expr.types as ir

DATASET_ID = "ibis_gbq_testing"
Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/bigquery/udf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import collections
import inspect
import itertools
from typing import Callable, Iterable, Literal, Mapping
from typing import TYPE_CHECKING, Callable, Literal

import ibis.expr.datatypes as dt
import ibis.expr.rules as rlz
Expand All @@ -12,6 +12,9 @@
from ibis.backends.bigquery.udf.core import PythonToJavaScriptTranslator
from ibis.legacy.udf.validate import validate_output_type

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

__all__ = ("udf",)

_udf_name_cache: dict[str, Iterable[int]] = collections.defaultdict(itertools.count)
Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from contextlib import closing, suppress
from functools import partial
from typing import TYPE_CHECKING, Any, Iterable, Iterator, Literal, Mapping
from typing import TYPE_CHECKING, Any, Literal

import clickhouse_connect as cc
import pyarrow as pa
Expand All @@ -25,6 +25,7 @@
from ibis.backends.clickhouse.datatypes import parse, serialize

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping
from pathlib import Path

import pandas as pd
Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/clickhouse/compiler/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@

from __future__ import annotations

from typing import Any, Mapping
from typing import TYPE_CHECKING, Any

import sqlglot as sg

import ibis.expr.operations as ops
import ibis.expr.types as ir
from ibis.backends.clickhouse.compiler.relations import translate_rel

if TYPE_CHECKING:
from collections.abc import Mapping


def translate(op: ops.TableNode, params: Mapping[ir.Value, Any]) -> sg.exp.Expression:
"""Translate an ibis operation to a sqlglot expression.
Expand Down
5 changes: 4 additions & 1 deletion ibis/backends/clickhouse/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import functools
from functools import partial
from operator import add, mul, sub
from typing import Any, Mapping
from typing import TYPE_CHECKING, Any

import sqlglot as sg
from sqlglot.dialects.dialect import rename_func
Expand All @@ -19,6 +19,9 @@
from ibis.backends.base.sql.registry import helpers
from ibis.backends.clickhouse.datatypes import serialize

if TYPE_CHECKING:
from collections.abc import Mapping

# TODO: Ideally we can translate bottom up a la `relations.py`
# TODO: Find a way to remove all the dialect="clickhouse" kwargs

Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/clickhouse/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import functools
from typing import TYPE_CHECKING, Literal, Mapping
from typing import TYPE_CHECKING, Literal

import sqlglot as sg
from sqlglot.expressions import ColumnDef, DataType
Expand All @@ -12,6 +12,8 @@
from ibis.formats.parser import TypeParser

if TYPE_CHECKING:
from collections.abc import Mapping

from sqlglot.expressions import DataTypeSize, Expression


Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/clickhouse/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import contextlib
import os
from typing import TYPE_CHECKING, Any, Callable, Iterable
from typing import TYPE_CHECKING, Any, Callable

import pytest

Expand All @@ -16,6 +16,7 @@
)

if TYPE_CHECKING:
from collections.abc import Iterable
from pathlib import Path

CLICKHOUSE_HOST = os.environ.get("IBIS_TEST_CLICKHOUSE_HOST", "localhost")
Expand Down
9 changes: 6 additions & 3 deletions ibis/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import importlib.metadata
import itertools
import sys
from functools import lru_cache
from functools import cache
from pathlib import Path
from typing import Any, Iterable
from typing import TYPE_CHECKING, Any

import _pytest
import numpy as np
Expand All @@ -23,6 +23,9 @@
from ibis.backends.base import CanCreateDatabase, CanCreateSchema, _get_backend_names
from ibis.conftest import WINDOWS

if TYPE_CHECKING:
from collections.abc import Iterable

TEST_TABLES = {
"functional_alltypes": ibis.schema(
{
Expand Down Expand Up @@ -327,7 +330,7 @@ def pytest_collection_modifyitems(session, config, items):
item.add_marker(marker)


@lru_cache(maxsize=None)
@cache
def _get_backends_to_test(
keep: tuple[str, ...] = (),
discard: tuple[str, ...] = (),
Expand Down
Loading

0 comments on commit 25946f9

Please sign in to comment.