Skip to content

Commit

Permalink
add test and ignore type checks (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: aandres3 <[email protected]>
  • Loading branch information
0x26res and aandres3 authored Oct 30, 2024
1 parent b3175a4 commit 30ed8b1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
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

0 comments on commit 30ed8b1

Please sign in to comment.