From e04c513589f90396499343a1141aedda3bffc2c3 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 9 Oct 2024 17:04:10 -0400 Subject: [PATCH] Test bad inputs --- rerun_py/src/dataframe.rs | 4 ++-- rerun_py/tests/unit/test_dataframe.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/rerun_py/src/dataframe.rs b/rerun_py/src/dataframe.rs index e4738c7ee44f..e140dcae2c70 100644 --- a/rerun_py/src/dataframe.rs +++ b/rerun_py/src/dataframe.rs @@ -213,7 +213,7 @@ impl<'py> IndexLike<'py> { let array = make_array(array.0.clone()); let int_array = array.as_any().downcast_ref::().ok_or_else(|| { - PyTypeError::new_err("Expected an array of integers for index values.") + PyTypeError::new_err("pyarrow.Array for IndexLike must be of type int64.") })?; let values: BTreeSet = int_array @@ -257,7 +257,7 @@ impl<'py> IndexLike<'py> { let int_array = array.as_any().downcast_ref::().ok_or_else(|| { PyTypeError::new_err( - "Expected an array of integers for index values.", + "pyarrow.Array for IndexLike must be of type int64.", ) })?; diff --git a/rerun_py/tests/unit/test_dataframe.py b/rerun_py/tests/unit/test_dataframe.py index ae648f8de069..8bacd9756762 100644 --- a/rerun_py/tests/unit/test_dataframe.py +++ b/rerun_py/tests/unit/test_dataframe.py @@ -5,6 +5,7 @@ import uuid import pyarrow as pa +import pytest import rerun as rr APP_ID = "rerun_example_test_recording" @@ -152,14 +153,14 @@ def test_index_values(self) -> None: assert table3 == table2 - ## Manually create a pyarrow array with no matches + # Manually create a pyarrow array with no matches view4 = view.filter_index_values(pa.array([8], type=pa.int64())) batches = view4.select() table4 = pa.Table.from_batches(batches, batches.schema) assert table4.num_rows == 0 - ## Manually create a chunked array with 1 match + # Manually create a chunked array with 1 match manual_chunked_selection = pa.chunked_array([ pa.array([2], type=pa.int64()), pa.array([3, 7, 8], type=pa.int64()), @@ -177,6 +178,16 @@ def test_index_values(self) -> None: assert table5.num_rows == 1 + # Exceptions + with pytest.raises(ValueError): + view.filter_index_values(pa.array([8, 8], type=pa.int64())) + + with pytest.raises(TypeError): + view.filter_index_values("1") + + with pytest.raises(TypeError): + view.filter_index_values(pa.array([1.0, 2.0], type=pa.float64())) + def test_view_syntax(self) -> None: good_content_expressions = [ {"points": rr.components.Position3D},