Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test and ignore type checks #82

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- insertion marker -->
## [v0.8.0](https://github.com/tradewelltech/protarrow/releases/tag/v0.8.0) - 2024-10-30

<small>[Compare with v0.7.0](https://github.com/tradewelltech/protarrow/compare/v0.7.0...v0.8.0)</small>

### Added

- Add ignore for type check ([08f591f](https://github.com/tradewelltech/protarrow/commit/08f591f5625f0cf3bd43ba2f61cb3c0a1795c0e2) by aandres3).

## [v0.7.0](https://github.com/tradewelltech/protarrow/releases/tag/v0.7.0) - 2024-10-14

<small>[Compare with v0.6.0](https://github.com/tradewelltech/protarrow/compare/v0.6.0...v0.7.0)</small>
Expand Down
14 changes: 8 additions & 6 deletions protarrow/proto_to_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,17 @@ def _messages_to_array(
nullable=_proto_field_nullable(field_descriptor, config),
)
)

if validity_mask is not None:
mask = pc.invert(pa.array(validity_mask, pa.bool_()))
elif len(arrays) == 0:
# This only happens when using empty messages.
mask = pa.repeat(False, len(messages)) # type: ignore[arg-type]
else:
mask = None
return pa.StructArray.from_arrays(
arrays=arrays,
fields=fields,
mask=(
pc.invert(pa.array(validity_mask, pa.bool_()))
if validity_mask is not None
else pa.repeat(False, len(messages))
),
mask=mask,
)


Expand Down
22 changes: 22 additions & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from protarrow.message_extractor import MessageExtractor
from protarrow.proto_to_arrow import (
NestedIterable,
_messages_to_array,
_repeated_proto_to_array,
field_descriptor_to_field,
message_type_to_schema,
Expand Down Expand Up @@ -199,6 +200,27 @@ def test_enum_values_as_int():
assert array.to_pylist() == [[0, 1, 0], [], []]


def test_messages_to_array_empty():
assert _messages_to_array(
[Empty(), Empty()], Empty.DESCRIPTOR, None, ProtarrowConfig()
) == pa.StructArray.from_arrays([], names=[], mask=pa.array([False, False]))


def test_empty_values():
records = [
ExampleMessage(empty_values=[Empty(), Empty(), Empty()]),
ExampleMessage(empty_values=[]),
ExampleMessage(),
]

array = _repeated_proto_to_array(
NestedIterable(records, lambda x: x.empty_values),
ExampleMessage.DESCRIPTOR.fields_by_name["empty_values"],
ProtarrowConfig(),
)
assert array.to_pylist() == [[{}, {}, {}], [], []]


@pytest.mark.parametrize(
["config", "expected"],
[
Expand Down