From 1eead42d2063e864838d6c24af429b0632ba10d2 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Wed, 13 Mar 2024 08:48:10 +0100 Subject: [PATCH 1/2] feat!: Change some error types to `SchemaError` --- crates/polars-core/src/utils/supertype.rs | 2 +- py-polars/tests/unit/functions/range/test_datetime_range.py | 4 ++-- py-polars/tests/unit/operations/test_transpose.py | 4 ++-- py-polars/tests/unit/test_errors.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/polars-core/src/utils/supertype.rs b/crates/polars-core/src/utils/supertype.rs index 92cf8e225400..6688428e329c 100644 --- a/crates/polars-core/src/utils/supertype.rs +++ b/crates/polars-core/src/utils/supertype.rs @@ -7,7 +7,7 @@ use super::*; /// Returns a [`PolarsError::ComputeError`] if no such data type exists. pub fn try_get_supertype(l: &DataType, r: &DataType) -> PolarsResult { get_supertype(l, r).ok_or_else( - || polars_err!(ComputeError: "failed to determine supertype of {} and {}", l, r), + || polars_err!(SchemaMismatch: "failed to determine supertype of {} and {}", l, r), ) } diff --git a/py-polars/tests/unit/functions/range/test_datetime_range.py b/py-polars/tests/unit/functions/range/test_datetime_range.py index b9873f833b4b..eebe12e2e176 100644 --- a/py-polars/tests/unit/functions/range/test_datetime_range.py +++ b/py-polars/tests/unit/functions/range/test_datetime_range.py @@ -7,7 +7,7 @@ import polars as pl from polars.datatypes import DTYPE_TEMPORAL_UNITS -from polars.exceptions import ComputeError, TimeZoneAwareConstructorWarning +from polars.exceptions import TimeZoneAwareConstructorWarning from polars.testing import assert_frame_equal, assert_series_equal if TYPE_CHECKING: @@ -176,7 +176,7 @@ def test_timezone_aware_datetime_range() -> None: ] with pytest.raises( - ComputeError, + pl.SchemaError, match="failed to determine supertype", ): pl.datetime_range( diff --git a/py-polars/tests/unit/operations/test_transpose.py b/py-polars/tests/unit/operations/test_transpose.py index 78a6222dfedf..7363d0b6aa3b 100644 --- a/py-polars/tests/unit/operations/test_transpose.py +++ b/py-polars/tests/unit/operations/test_transpose.py @@ -5,7 +5,7 @@ import pytest import polars as pl -from polars.exceptions import ComputeError, StringCacheMismatchError +from polars.exceptions import StringCacheMismatchError from polars.testing import assert_frame_equal, assert_series_equal @@ -31,7 +31,7 @@ def test_transpose_tz_naive_and_tz_aware() -> None: ) df = df.with_columns(pl.col("b").dt.replace_time_zone("Asia/Kathmandu")) with pytest.raises( - ComputeError, + pl.SchemaError, match=r"failed to determine supertype of datetime\[μs\] and datetime\[μs, Asia/Kathmandu\]", ): df.transpose() diff --git a/py-polars/tests/unit/test_errors.py b/py-polars/tests/unit/test_errors.py index 91a8e2fe3825..baa691e0ee5e 100644 --- a/py-polars/tests/unit/test_errors.py +++ b/py-polars/tests/unit/test_errors.py @@ -310,7 +310,7 @@ def test_duplicate_columns_arg_csv() -> None: def test_datetime_time_add_err() -> None: - with pytest.raises(pl.ComputeError): + with pytest.raises(pl.SchemaError, match="failed to determine supertype"): pl.Series([datetime(1970, 1, 1, 0, 0, 1)]) + pl.Series([time(0, 0, 2)]) From 47c8d9242c666e5e6422e13e4ac400efeb784453 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Thu, 23 May 2024 15:16:14 +0200 Subject: [PATCH 2/2] AnyValue --- crates/polars-core/src/series/any_value.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/polars-core/src/series/any_value.rs b/crates/polars-core/src/series/any_value.rs index a3e721c3d281..79e3b5911273 100644 --- a/crates/polars-core/src/series/any_value.rs +++ b/crates/polars-core/src/series/any_value.rs @@ -430,7 +430,7 @@ fn any_values_to_decimal( continue; } else { polars_bail!( - ComputeError: "unable to convert any-value of dtype {} to decimal", av.dtype(), + SchemaMismatch: "unable to convert any-value of dtype {} to decimal", av.dtype(), ); }; scale_range = match scale_range { @@ -448,7 +448,7 @@ fn any_values_to_decimal( // Scale is provided but is lower than actual. // TODO: Do we want lossy conversions here or not? polars_bail!( - ComputeError: + SchemaMismatch: "unable to losslessly convert any-value of scale {s_max} to scale {}", scale, ); } @@ -473,7 +473,7 @@ fn any_values_to_decimal( } else { let factor = 10_i128.pow((scale - s_av) as _); // this cast is safe builder.append_value(v.checked_mul(factor).ok_or_else(|| { - polars_err!(ComputeError: "overflow while converting to decimal scale {}", scale) + polars_err!(SchemaMismatch: "overflow while converting to decimal scale {}", scale) })?); } } @@ -723,7 +723,7 @@ fn any_values_to_object( AnyValue::Object(val) => builder.append_value(val.as_any()), AnyValue::Null => builder.append_null(), _ => { - polars_bail!(ComputeError: "expected object"); + polars_bail!(SchemaMismatch: "expected object"); }, } }