Skip to content

Commit

Permalink
feat!: Update some error types to more appropriate variants (#15030)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Jun 5, 2024
1 parent 6db670d commit a3d65df
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/polars-core/src/series/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
);
}
Expand All @@ -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)
})?);
}
}
Expand Down Expand Up @@ -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");
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/utils/supertype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataType> {
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),
)
}

Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/functions/range/test_datetime_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/operations/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])


Expand Down

0 comments on commit a3d65df

Please sign in to comment.