Skip to content

Commit

Permalink
drop redundant definition of PyCapsuleStreamHolder test object
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Feb 7, 2025
1 parent 8b2c832 commit ac1b338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
43 changes: 1 addition & 42 deletions py-polars/tests/unit/constructors/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from polars.dependencies import dataclasses, pydantic
from polars.exceptions import DuplicateError, ShapeError
from polars.testing import assert_frame_equal, assert_series_equal
from tests.unit.utils.pycapsule_utils import PyCapsuleArrayHolder, PyCapsuleStreamHolder

if TYPE_CHECKING:
import sys
Expand Down Expand Up @@ -1699,48 +1700,6 @@ def test_array_construction() -> None:
assert df.rows() == [("a", [1, 2, 3]), ("b", [2, 3, 4])]


class PyCapsuleStreamHolder:
"""
Hold the Arrow C Stream pycapsule.
A class that exposes the Arrow C Stream interface via Arrow PyCapsules. This
ensures that the consumer is seeing _only_ the `__arrow_c_stream__` dunder, and that
nothing else (e.g. the dataframe or array interface) is actually being used.
"""

arrow_obj: Any

def __init__(self, arrow_obj: object) -> None:
self.arrow_obj = arrow_obj

def __arrow_c_stream__(self, requested_schema: object = None) -> object:
return self.arrow_obj.__arrow_c_stream__(requested_schema)

def __iter__(self) -> None:
return

def __next__(self) -> None:
return


class PyCapsuleArrayHolder:
"""
Hold the Arrow C Array pycapsule.
A class that exposes _only_ the Arrow C Array interface via Arrow PyCapsules. This
ensures that the consumer is seeing _only_ the `__arrow_c_array__` dunder, and that
nothing else (e.g. the dataframe or array interface) is actually being used.
"""

arrow_obj: Any

def __init__(self, arrow_obj: object) -> None:
self.arrow_obj = arrow_obj

def __arrow_c_array__(self, requested_schema: object = None) -> object:
return self.arrow_obj.__arrow_c_array__(requested_schema)


@pytest.mark.may_fail_auto_streaming
def test_pycapsule_interface(df: pl.DataFrame) -> None:
df = df.rechunk()
Expand Down
33 changes: 27 additions & 6 deletions py-polars/tests/unit/utils/pycapsule_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ class PyCapsuleStreamHolder:
"""
Hold the Arrow C Stream pycapsule.
A class that exposes _only_ the Arrow C Stream interface via Arrow PyCapsules.
This ensures that pyarrow is seeing _only_ the `__arrow_c_stream__` dunder, and
that nothing else (e.g. the dataframe or array interface) is actually being
used.
This is used by tests across multiple files.
A class that exposes the Arrow C Stream interface via Arrow PyCapsules. This
ensures that the consumer is seeing _only_ the `__arrow_c_stream__` dunder, and that
nothing else (e.g. the dataframe or array interface) is actually being used.
"""

arrow_obj: Any
Expand All @@ -20,3 +17,27 @@ def __init__(self, arrow_obj: object) -> None:

def __arrow_c_stream__(self, requested_schema: object = None) -> object:
return self.arrow_obj.__arrow_c_stream__(requested_schema)

def __iter__(self) -> None:
return

def __next__(self) -> None:
return


class PyCapsuleArrayHolder:
"""
Hold the Arrow C Array pycapsule.
A class that exposes _only_ the Arrow C Array interface via Arrow PyCapsules. This
ensures that the consumer is seeing _only_ the `__arrow_c_array__` dunder, and that
nothing else (e.g. the dataframe or array interface) is actually being used.
"""

arrow_obj: Any

def __init__(self, arrow_obj: object) -> None:
self.arrow_obj = arrow_obj

def __arrow_c_array__(self, requested_schema: object = None) -> object:
return self.arrow_obj.__arrow_c_array__(requested_schema)

0 comments on commit ac1b338

Please sign in to comment.