This is an automated email from the ASF dual-hosted git repository.
apitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new ed5e1b4166 GH-40379: [Python] Fix byte_width for binary(0) + fix
hypothesis tests (#40381)
ed5e1b4166 is described below
commit ed5e1b4166c8d8984a3d01a6a14b939e9a4c8ce4
Author: Joris Van den Bossche <[email protected]>
AuthorDate: Thu Mar 7 12:05:12 2024 +0100
GH-40379: [Python] Fix byte_width for binary(0) + fix hypothesis tests
(#40381)
### Rationale for this change
Fixing the hypothesis tests:
- fixup untested changes to the strategies from
https://github.com/apache/arrow/pull/40160
- fix a bug in the `byte_width` attribute discovered by hypothesis
(introduced by https://github.com/apache/arrow/pull/39592)
* GitHub Issue: #40379
Authored-by: Joris Van den Bossche <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
python/pyarrow/tests/strategies.py | 8 ++++++--
python/pyarrow/tests/test_types.py | 5 +++--
python/pyarrow/types.pxi | 2 +-
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/python/pyarrow/tests/strategies.py
b/python/pyarrow/tests/strategies.py
index 7affe815a2..db0aa13971 100644
--- a/python/pyarrow/tests/strategies.py
+++ b/python/pyarrow/tests/strategies.py
@@ -167,8 +167,8 @@ def list_types(item_strategy=primitive_types):
pa.list_,
item_strategy,
st.integers(min_value=0, max_value=16)
- ),
- st.builds(pa.list_view, item_strategy),
+ ) |
+ st.builds(pa.list_view, item_strategy) |
st.builds(pa.large_list_view, item_strategy)
)
@@ -322,6 +322,10 @@ def arrays(draw, type, size=None, nullable=True):
value = _pylist(ty.value_type, size=size, nullable=nullable)
elif pa.types.is_fixed_size_list(ty):
value = _pylist(ty.value_type, size=ty.list_size, nullable=nullable)
+ elif pa.types.is_list_view(ty):
+ value = _pylist(ty.value_type, size=size, nullable=nullable)
+ elif pa.types.is_large_list_view(ty):
+ value = _pylist(ty.value_type, size=size, nullable=nullable)
elif pa.types.is_dictionary(ty):
values = _pylist(ty.value_type, size=size, nullable=nullable)
return pa.array(draw(values), type=ty)
diff --git a/python/pyarrow/tests/test_types.py
b/python/pyarrow/tests/test_types.py
index 1d132a6af8..13f6d83e80 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -955,11 +955,12 @@ def test_bit_and_byte_width():
(pa.date32(), 32, 4),
(pa.decimal128(19, 4), 128, 16),
(pa.decimal256(76, 38), 256, 32),
- (pa.binary(42), 42 * 8, 42)
+ (pa.binary(42), 42 * 8, 42),
+ (pa.binary(0), 0, 0),
]:
assert ty.bit_width == expected_bit_width
- if expected_byte_width == 0:
+ if 0 < expected_bit_width < 8:
with pytest.raises(ValueError, match="Less than one byte"):
ty.byte_width
else:
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index ec05100caf..6cbad8eeb6 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -275,7 +275,7 @@ cdef class DataType(_Weakrefable):
if ty == nullptr:
raise ValueError("Non-fixed width type")
byte_width = ty.byte_width()
- if byte_width == 0:
+ if byte_width == 0 and self.bit_width != 0:
raise ValueError("Less than one byte")
return byte_width