diff --git a/protarrow/cast_to_proto.py b/protarrow/cast_to_proto.py index bce3716..68b2f91 100644 --- a/protarrow/cast_to_proto.py +++ b/protarrow/cast_to_proto.py @@ -126,19 +126,18 @@ def _cast_array( # TODO: remove when https://github.com/apache/arrow/issues/40750 is fixed # and library is pinned to pyarrow>=17.0.0 - offsets = maybe_copy_offsets(array.offsets) keys = _cast_array(keys, key_field, config) values = _cast_array(values, value_field, config) if config.map_as_list: return _map_as_list_from_arrays( - offsets=offsets, + offsets=array.offsets, keys=keys, values=values, config=config, ) else: - return pa.MapArray.from_arrays(offsets, keys, values).cast( + return pa.MapArray.from_arrays(array.offsets, keys, values).cast( pa.map_( keys.type, pa.field( @@ -251,11 +250,3 @@ def cast_table( ], proto_schema, ) - - -def maybe_copy_offsets(offsets: pa.Array) -> pa.Array: - if offsets.offset != 0: - # TODO: this it not efficient, find a way to copy in arrow - return pa.array(offsets.to_pylist(), offsets.type) - else: - return offsets diff --git a/pyproject.toml b/pyproject.toml index 311e76d..e6d05be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ "Programming Language :: Python :: 3.14", ] dynamic = [ "version" ] -dependencies = [ "googleapis-common-protos", "protobuf", "pyarrow" ] +dependencies = [ "googleapis-common-protos", "protobuf", "pyarrow>=17" ] urls."Bug Tracker" = "https://github.com/tradewelltech/protarrow/issues" urls.Changelog = "https://github.com/tradewelltech/protarrow/blob/main/CHANGELOG.md" documentation = "https://protarrow.readthedocs.io/en/latest/" diff --git a/tests/test_conversion.py b/tests/test_conversion.py index 264826e..23a653b 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -23,7 +23,6 @@ cast_table, get_arrow_default_value, get_casted_array, - maybe_copy_offsets, ) from protarrow.common import M, ProtarrowConfig, offset_values_array from protarrow.message_extractor import MessageExtractor @@ -799,6 +798,8 @@ def test_cast_map_offset(): ) assert _cast_array(from_array, field, ProtarrowConfig()) == to_array + # Test it works with offset array / slice views. + # https://github.com/apache/arrow/issues/40750 assert _cast_array(from_array[1:], field, ProtarrowConfig()) == to_array[1:] @@ -825,18 +826,6 @@ def test_cast_list_offset(): assert _cast_array(from_array[1:], field, ProtarrowConfig()) == to_array[1:] -def test_maybe_copy_offsets(): - array = pa.array([1, 2, 3], pa.int32()) - assert maybe_copy_offsets(array) is array # no copy - view = array[1:] - copy = maybe_copy_offsets(array[1:]) - assert copy == view - assert copy is not view # copy - assert copy.offset == 0 - # Sadly pa.array is highly optimized - assert pa.array(array) is array - - def test_map_cast(): array = pa.array( [ diff --git a/uv.lock b/uv.lock index 1634d56..0d450a1 100644 --- a/uv.lock +++ b/uv.lock @@ -663,6 +663,7 @@ wheels = [ name = "griffelib" version = "2.0.0" source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ad/06/eccbd311c9e2b3ca45dbc063b93134c57a1ccc7607c5e545264ad092c4a9/griffelib-2.0.0.tar.gz", hash = "sha256:e504d637a089f5cab9b5daf18f7645970509bf4f53eda8d79ed71cce8bd97934", size = 166312, upload-time = "2026-03-23T21:06:55.954Z" } wheels = [ { url = "https://files.pythonhosted.org/packages/4d/51/c936033e16d12b627ea334aaaaf42229c37620d0f15593456ab69ab48161/griffelib-2.0.0-py3-none-any.whl", hash = "sha256:01284878c966508b6d6f1dbff9b6fa607bc062d8261c5c7253cb285b06422a7f", size = 142004, upload-time = "2026-02-09T19:09:40.561Z" }, ] @@ -1440,15 +1441,15 @@ dev = [ requires-dist = [ { name = "googleapis-common-protos" }, { name = "protobuf" }, - { name = "pyarrow" }, + { name = "pyarrow", specifier = ">=17.0.0" }, ] [package.metadata.requires-dev] dev = [ - { name = "coverage", specifier = ">=6.5.0" }, + { name = "coverage", specifier = ">=6.5" }, { name = "flake8", specifier = ">=5.0.4" }, - { name = "git-changelog", specifier = ">=2.2.0" }, - { name = "grpcio-tools", specifier = ">=1.46.0" }, + { name = "git-changelog", specifier = ">=2.2" }, + { name = "grpcio-tools", specifier = ">=1.46" }, { name = "inflection", specifier = ">=0.5.1" }, { name = "isort", specifier = ">=5.10.1" }, { name = "jinja2", specifier = ">=3.1.2" }, @@ -1456,12 +1457,12 @@ dev = [ { name = "mkdocs-material", specifier = ">=9.0.3" }, { name = "mkdocstrings", extras = ["python"], specifier = ">=0.21.2" }, { name = "pip-tools", specifier = ">=6.12.1" }, - { name = "pre-commit", specifier = ">=2.20.0" }, - { name = "pylint", specifier = ">=2.15.0" }, - { name = "pytest", specifier = ">=7.2.0" }, - { name = "pytest-benchmark", specifier = ">=4.0.0" }, + { name = "pre-commit", specifier = ">=2.20" }, + { name = "pylint", specifier = ">=2.15" }, + { name = "pytest", specifier = ">=7.2" }, + { name = "pytest-benchmark", specifier = ">=4" }, { name = "pytest-cov" }, - { name = "pytest-xdist", specifier = ">=3.1.0" }, + { name = "pytest-xdist", specifier = ">=3.1" }, { name = "ruff" }, ]