Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 14, 2023
1 parent f0d05a7 commit 3c839e3
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/nano-arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ arrow-array = { workspace = true, optional = true }
arrow-buffer = { workspace = true, optional = true }
arrow-data = { workspace = true, optional = true }
arrow-schema = { workspace = true, optional = true }
parquet2 = { workspace = true, optional = true, default-features = false, features = ["async"] }
parquet2 = { workspace = true, optional = true, features = ["async"] }

[dev-dependencies]
avro-rs = { version = "0.13", features = ["snappy"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/nano-arrow/src/io/ipc/read/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{Dictionaries, IpcBuffer, Node};
use crate::array::*;
use crate::datatypes::{DataType, Field, PhysicalType};
use crate::io::ipc::IpcField;
use crate::{match_integer_type, with_match_primitive_type, with_match_primitive_type_full};
use crate::{match_integer_type, with_match_primitive_type_full};

#[allow(clippy::too_many_arguments)]
pub fn read<R: Read + Seek>(
Expand Down
2 changes: 2 additions & 0 deletions crates/nano-arrow/src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ macro_rules! with_match_primitive_type_full {(
) => ({
macro_rules! __with_ty__ {( $_ $T:ident ) => ( $($body)* )}
use $crate::datatypes::PrimitiveType::*;
use $crate::types::{f16};
match $key_type {
Int8 => __with_ty__! { i8 },
Int16 => __with_ty__! { i16 },
Expand All @@ -36,6 +37,7 @@ macro_rules! with_match_primitive_type_full {(
UInt32 => __with_ty__! { u32 },
UInt64 => __with_ty__! { u64 },
Int128 => __with_ty__! { i128 },
Float16 => __with_ty__! { f16 },
Float32 => __with_ty__! { f32 },
Float64 => __with_ty__! { f64 },
_ => panic!("operator does not support primitive `{:?}`",
Expand Down
10 changes: 2 additions & 8 deletions crates/polars-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl From<object_store::Error> for PolarsError {
#[cfg(feature = "parquet2")]
impl From<parquet2::error::Error> for PolarsError {
fn from(err: parquet2::error::Error) -> Self {
PolarsError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
format!("parquet error: {err:?}"),
))
polars_err!(ComputeError: "parquet error: {err:?}")
}
}

Expand All @@ -118,10 +115,7 @@ impl From<simdutf8::basic::Utf8Error> for PolarsError {
#[cfg(feature = "arrow-format")]
impl From<arrow_format::ipc::planus::Error> for PolarsError {
fn from(err: arrow_format::ipc::planus::Error) -> Self {
PolarsError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
format!("flatbuffers error: {err:?}"),
))
polars_err!(ComputeError: "parquet error: {err:?}")
}
}

Expand Down
5 changes: 3 additions & 2 deletions py-polars/polars/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class UnsuitableSQLError(ValueError):
"""Exception raised when unsuitable SQL is given to a database method."""


class ArrowError(Exception): # type: ignore[no-redef]
"""deprecated will be removed"""
class ArrowError(Exception):
"""deprecated will be removed."""


__all__ = [
"ArrowError",
Expand Down
5 changes: 2 additions & 3 deletions py-polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ use pyo3::wrap_pyfunction;
use crate::conversion::Wrap;
use crate::dataframe::PyDataFrame;
use crate::error::{
ColumnNotFoundError, ComputeError, DuplicateError, InvalidOperationError,
NoDataError, OutOfBoundsError, PyPolarsErr, SchemaError, SchemaFieldNotFoundError,
StructFieldNotFoundError,
ColumnNotFoundError, ComputeError, DuplicateError, InvalidOperationError, NoDataError,
OutOfBoundsError, PyPolarsErr, SchemaError, SchemaFieldNotFoundError, StructFieldNotFoundError,
};
use crate::expr::PyExpr;
use crate::functions::string_cache::PyStringCacheHolder;
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def test_file_buffer() -> None:
f.write(b"1,2,3,4,5,6\n7,8,9,10,11,12")
f.seek(0)
# check if not fails on TryClone and Length impl in file.rs
with pytest.raises(OSError):
with pytest.raises(pl.ComputeError):
pl.read_parquet(f)


Expand Down
5 changes: 3 additions & 2 deletions py-polars/tests/unit/datatypes/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import polars as pl
from polars.datatypes import DATETIME_DTYPES, DTYPE_TEMPORAL_UNITS, TEMPORAL_DTYPES
from polars.exceptions import ArrowError, ComputeError, TimeZoneAwareConstructorWarning
from polars.exceptions import ComputeError, TimeZoneAwareConstructorWarning
from polars.testing import (
assert_frame_equal,
assert_series_equal,
Expand Down Expand Up @@ -2177,7 +2177,8 @@ def test_replace_time_zone_ambiguous_with_use_earliest(
def test_replace_time_zone_ambiguous_raises() -> None:
ts = pl.Series(["2018-10-28 02:30:00"]).str.strptime(pl.Datetime)
with pytest.raises(
pl.ComputeError, match="Please use `ambiguous` to tell how it should be localized"
pl.InvalidOperationError,
match="Please use `ambiguous` to tell how it should be localized",
):
ts.dt.replace_time_zone("Europe/Brussels")

Expand Down
10 changes: 5 additions & 5 deletions py-polars/tests/unit/namespaces/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pytest

import polars as pl
from polars.exceptions import ArrowError, ComputeError, TimeZoneAwareConstructorWarning
from polars.exceptions import ComputeError, TimeZoneAwareConstructorWarning
from polars.testing import assert_series_equal

if TYPE_CHECKING:
Expand Down Expand Up @@ -459,14 +459,14 @@ def test_strptime_invalid_timezone() -> None:

def test_to_datetime_ambiguous_or_non_existent() -> None:
with pytest.raises(
ArrowError,
pl.InvalidOperationError,
match="datetime '2021-11-07 01:00:00' is ambiguous in time zone 'US/Central'",
):
pl.Series(["2021-11-07 01:00"]).str.to_datetime(
time_unit="us", time_zone="US/Central"
)
with pytest.raises(
ArrowError,
pl.InvalidOperationError,
match="datetime '2021-03-28 02:30:00' is non-existent in time zone 'Europe/Warsaw'",
):
pl.Series(["2021-03-28 02:30"]).str.to_datetime(
Expand Down Expand Up @@ -643,7 +643,7 @@ def test_to_datetime_use_earliest(exact: bool) -> None:
)
expected = datetime(2020, 10, 25, 1, fold=1, tzinfo=ZoneInfo("Europe/London"))
assert result == expected
with pytest.raises(ArrowError):
with pytest.raises(pl.InvalidOperationError):
pl.Series(["2020-10-25 01:00"]).str.to_datetime(
time_zone="Europe/London",
exact=exact,
Expand All @@ -670,7 +670,7 @@ def test_strptime_use_earliest(exact: bool) -> None:
)
expected = datetime(2020, 10, 25, 1, fold=1, tzinfo=ZoneInfo("Europe/London"))
assert result == expected
with pytest.raises(ArrowError):
with pytest.raises(pl.InvalidOperationError):
pl.Series(["2020-10-25 01:00"]).str.strptime(
pl.Datetime("us", "Europe/London"),
exact=exact,
Expand Down

0 comments on commit 3c839e3

Please sign in to comment.