Skip to content
Open
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
18 changes: 13 additions & 5 deletions .github/workflows/ibis-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ jobs:
- "3.10"
- "3.14"
pyarrow:
- true
- false
- none
- latest
- old
exclude:
- python-version: "3.14"
pyarrow: old
steps:
- name: checkout
uses: actions/checkout@v6
Expand All @@ -76,9 +80,13 @@ jobs:
if: matrix.os == 'windows-latest'
run: choco install graphviz

- name: install numpy/pandas/pyarrow
if: matrix.pyarrow
run: pip install numpy pandas pyarrow pyarrow-hotfix
- name: install numpy/pandas/pyarrow (latest)
if: matrix.pyarrow == 'latest'
run: pip install numpy pandas pyarrow

- name: install numpy/pandas/pyarrow (old)
if: matrix.pyarrow == 'old'
run: pip install "numpy<2" pandas pyarrow==10.0.1 pyarrow-hotfix

- uses: extractions/setup-just@v3
env:
Expand Down
9 changes: 6 additions & 3 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _import_pyarrow():
"Exporting to arrow formats requires `pyarrow` but it is not installed"
)
else:
import pyarrow_hotfix # noqa: F401
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

return pyarrow

Expand Down Expand Up @@ -1607,9 +1607,10 @@ class PyArrowExampleLoader(ExampleLoader):
temporary_example: bool = True

def _load_parquet(self, *, path: str | Path, table_name: str) -> ir.Table:
import pyarrow_hotfix # noqa: F401, I001
import pyarrow.parquet as pq

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

table = pq.read_table(path)
return self.create_table(
table_name,
Expand All @@ -1619,10 +1620,12 @@ def _load_parquet(self, *, path: str | Path, table_name: str) -> ir.Table:
)

def _load_csv(self, *, path: str | Path, table_name: str) -> ir.Table:
import pyarrow_hotfix # noqa: F401, I001

import pyarrow as pa
import pyarrow.csv

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

# The convert options lets pyarrow treat empty strings as null for
# string columns, but not quoted empty strings.
table = pyarrow.csv.read_csv(
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/athena/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import TYPE_CHECKING, Any

import fsspec
import pyarrow_hotfix # noqa: F401
import pyathena
import sqlglot as sg
import sqlglot.expressions as sge
Expand All @@ -27,6 +26,7 @@
from ibis.backends import CanCreateDatabase, NoExampleLoader, UrlFromPath
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import AlterTable, RenameTable
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if TYPE_CHECKING:
from collections.abc import Callable, Mapping
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import clickhouse_connect as cc
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import sqlglot as sg
import sqlglot.expressions as sge
import toolz
Expand All @@ -35,6 +34,7 @@
from ibis.backends.clickhouse.converter import ClickHousePandasData
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import C
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/databricks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import databricks.sql
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import sqlglot as sg
import sqlglot.expressions as sge

Expand All @@ -30,6 +29,7 @@
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import STAR, AlterTable, RenameTable
from ibis.backends.sql.datatypes import DatabricksType
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Mapping
Expand Down
9 changes: 7 additions & 2 deletions ibis/backends/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import datafusion as df
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import sqlglot as sg
import sqlglot.expressions as sge

Expand All @@ -32,10 +31,16 @@
)
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import C
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
from ibis.common.dispatch import lazy_singledispatch
from ibis.expr.operations.udf import InputType
from ibis.formats.pyarrow import PyArrowSchema, PyArrowType
from ibis.util import gen_name, normalize_filename, normalize_filenames, warn_deprecated
from ibis.util import (
gen_name,
normalize_filename,
normalize_filenames,
warn_deprecated,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easy, revert this change that is just restyling so our git diff is cleaner. But not a blocker if you don't get to it.

)

try:
from datafusion import ExecutionContext as SessionContext
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/datafusion/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import pyarrow as pa
import pyarrow.compute as pc
import pyarrow_hotfix # noqa: F401

import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401


def _extract_epoch_seconds(array) -> dt.int32:
Expand Down
4 changes: 1 addition & 3 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import STAR, AlterTable, C, RenameTable
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got moved up here to the top level. So now as soon as you import this file, you need pyarrow installed. I'm guessing you did this to reduce the number of imports from 3 to 1, which is a nice simplification. But I think we should remain more conservative, and only import_to_try_pyarrow_hotfix lazily when we actually DO need pyarrow. So move this back to the original callsites.

The one exception is I don't think we need to import_to_try_pyarrow_hotfix in the if TYPE_CHECKING block?? So I think you can just delete that one??

from ibis.common.dispatch import lazy_singledispatch
from ibis.expr.operations.udf import InputType

Expand All @@ -42,7 +43,6 @@
import pandas as pd
import polars as pl
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import torch
from fsspec import AbstractFileSystem

Expand Down Expand Up @@ -1380,7 +1380,6 @@ def to_pyarrow_batches(
The number of rows to fetch per batch
"""
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

self._run_pre_execute_hooks(expr)
table = expr.as_table()
Expand Down Expand Up @@ -1422,7 +1421,6 @@ def execute(
"""Execute an expression."""
import pandas as pd
import pyarrow.types as pat
import pyarrow_hotfix # noqa: F401

from ibis.backends.duckdb.converter import DuckDBPandasData

Expand Down
13 changes: 8 additions & 5 deletions ibis/backends/flink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ def create_table(
"""
import pandas as pd
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

import ibis.expr.types as ir
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if obj is None and schema is None:
raise exc.IbisError("`schema` or `obj` is required")
Expand Down Expand Up @@ -937,7 +937,8 @@ def insert(
"""
import pandas as pd
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if isinstance(obj, ir.Table):
statement = InsertSelect(
Expand Down Expand Up @@ -982,7 +983,8 @@ def to_pyarrow(
**kwargs: Any,
) -> pa.Table:
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

pyarrow_batches = iter(
self.to_pyarrow_batches(expr, params=params, limit=limit, **kwargs)
Expand All @@ -1009,7 +1011,8 @@ def to_pyarrow_batches(
**kwargs: Any,
):
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

ibis_table = expr.as_table()

Expand Down Expand Up @@ -1059,12 +1062,12 @@ def _from_pyflink_table_to_pyarrow_batches(
chunk_size: int | None = None,
):
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
from pyflink.java_gateway import get_gateway
from pyflink.table.serializers import ArrowSerializer
from pyflink.table.types import create_arrow_schema

from ibis.backends.flink.datatypes import get_field_data_types
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
# Note (mehmet): Implementation of this is based on
# pyflink/table/table.py: to_pandas().

Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/impala/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,8 @@ def to_pyarrow(
**kwargs: Any,
) -> pa.Table:
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
from ibis.formats.pyarrow import PyArrowData

self._run_pre_execute_hooks(expr)
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/pyspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ def to_pyarrow(
"PySpark in streaming mode does not support to_pyarrow"
)
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
from ibis.formats.pyarrow import PyArrowData

table_expr = expr.as_table()
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from urllib.request import urlcleanup, urlretrieve

import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import sqlglot as sg
import sqlglot.expressions as sge

Expand All @@ -36,6 +35,7 @@
from ibis.backends.snowflake.converter import SnowflakePandasData
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import STAR
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

if TYPE_CHECKING:
from collections.abc import Generator, Iterator, Mapping
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/snowflake/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from urllib.request import urlretrieve

import pyarrow.parquet as pq
import pyarrow_hotfix # noqa: F401
Comment thread
NickCrews marked this conversation as resolved.
import pytest
import snowflake.connector as sc
import sqlglot as sg
Expand All @@ -19,6 +18,7 @@
from ibis.backends.conftest import TEST_TABLES
from ibis.backends.sql.datatypes import SnowflakeType
from ibis.backends.tests.base import BackendTest
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
from ibis.formats.pyarrow import PyArrowSchema

if TYPE_CHECKING:
Expand Down
9 changes: 9 additions & 0 deletions ibis/common/import_to_try_pyarrow_hotfix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from __future__ import annotations

import pyarrow as pa

if tuple(int(x) for x in pa.__version__.split(".")[:3]) < (14, 0, 1):
try:
import pyarrow_hotfix # noqa: F401
except ImportError:
raise ImportError("pyarrow_hotfix should be installed for pyarrow<14.0.1")
3 changes: 2 additions & 1 deletion ibis/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def to_polars(self, schema: Schema) -> pl.DataFrame: # pragma: no cover

def to_pyarrow_bytes(self, schema: Schema) -> bytes:
import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

data = self.to_pyarrow(schema=schema)
out = pa.BufferOutputStream()
Expand Down
3 changes: 2 additions & 1 deletion ibis/formats/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def to_pyarrow(self, schema: sch.Schema) -> pa.Table:
from decimal import Decimal

import pyarrow as pa
import pyarrow_hotfix # noqa: F401

from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401

pyarrow_schema = PyArrowSchema.from_ibis(schema)

Expand Down
2 changes: 1 addition & 1 deletion ibis/formats/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from typing import TYPE_CHECKING, Any

import pyarrow as pa
import pyarrow_hotfix # noqa: F401

import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
from ibis.common import import_to_try_pyarrow_hotfix # noqa: F401
from ibis.expr.schema import Schema
from ibis.formats import DataMapper, SchemaMapper, TableProxy, TypeMapper
from ibis.util import V
Expand Down