Skip to content

Commit

Permalink
fix: Expand Int128 testing and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley committed Dec 29, 2024
1 parent f5f4cb5 commit c9ba7bf
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 156 deletions.
1 change: 1 addition & 0 deletions crates/polars-python/src/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl PyArrowPrimitiveType for Int8Type {}
impl PyArrowPrimitiveType for Int16Type {}
impl PyArrowPrimitiveType for Int32Type {}
impl PyArrowPrimitiveType for Int64Type {}
impl PyArrowPrimitiveType for Int128Type {}
impl PyArrowPrimitiveType for Float32Type {}
impl PyArrowPrimitiveType for Float64Type {}

Expand Down
11 changes: 11 additions & 0 deletions crates/polars-python/src/series/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ impl PySeries {
)?;
ca.into_series()
},
Some(DataType::Int128) => {
let ca: Int128Chunked = dispatch_apply!(
series,
apply_lambda_with_primitive_out_type,
py,
function,
0,
None
)?;
ca.into_series()
},
Some(DataType::UInt8) => {
let ca: UInt8Chunked = dispatch_apply!(
series,
Expand Down
1 change: 1 addition & 0 deletions crates/polars-python/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ macro_rules! apply_method_all_arrow_series2 {
DataType::Int16 => $self.i16().unwrap().$method($($args),*),
DataType::Int32 => $self.i32().unwrap().$method($($args),*),
DataType::Int64 => $self.i64().unwrap().$method($($args),*),
DataType::Int128 => $self.i128().unwrap().$method($($args),*),
DataType::Float32 => $self.f32().unwrap().$method($($args),*),
DataType::Float64 => $self.f64().unwrap().$method($($args),*),
DataType::Date => $self.date().unwrap().$method($($args),*),
Expand Down
14 changes: 3 additions & 11 deletions py-polars/tests/unit/dataframe/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import polars as pl
from polars.testing import assert_frame_equal, assert_series_equal
from polars.testing.parametric import column, dataframes
from tests.unit.conftest import INTEGER_DTYPES, SIGNED_INTEGER_DTYPES


@given(
Expand Down Expand Up @@ -309,16 +310,7 @@ def test_df_getitem() -> None:
assert_frame_equal(df[pl.Series("", ["a", "b"])], df)

# pl.Series: positive idxs or empty idxs for row selection.
for pl_dtype in (
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
):
for pl_dtype in INTEGER_DTYPES:
assert_frame_equal(
df[pl.Series("", [1, 0, 3, 2, 3, 0], dtype=pl_dtype)],
pl.DataFrame(
Expand All @@ -328,7 +320,7 @@ def test_df_getitem() -> None:
assert df[pl.Series("", [], dtype=pl_dtype)].columns == ["a", "b"]

# pl.Series: positive and negative idxs for row selection.
for pl_dtype in (pl.Int8, pl.Int16, pl.Int32, pl.Int64):
for pl_dtype in SIGNED_INTEGER_DTYPES:
assert_frame_equal(
df[pl.Series("", [-1, 0, -3, -2, 3, -4], dtype=pl_dtype)],
pl.DataFrame(
Expand Down
20 changes: 3 additions & 17 deletions py-polars/tests/unit/datatypes/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
SchemaError,
)
from polars.testing import assert_frame_equal, assert_series_equal
from tests.unit.conftest import INTEGER_DTYPES

if sys.version_info >= (3, 11):
from enum import StrEnum
Expand Down Expand Up @@ -498,10 +499,7 @@ def test_enum_categories_series_zero_copy() -> None:
assert result_dtype == dtype


@pytest.mark.parametrize(
"dtype",
[pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Int8, pl.Int16, pl.Int32, pl.Int64],
)
@pytest.mark.parametrize("dtype", INTEGER_DTYPES)
def test_enum_cast_from_other_integer_dtype(dtype: pl.DataType) -> None:
enum_dtype = pl.Enum(["a", "b", "c", "d"])
series = pl.Series([1, 2, 3, 3, 2, 1], dtype=dtype)
Expand Down Expand Up @@ -585,19 +583,7 @@ def test_category_comparison_subset() -> None:
assert out["dt1"].dtype != out["dt2"].dtype


@pytest.mark.parametrize(
"dt",
[
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
],
)
@pytest.mark.parametrize("dt", INTEGER_DTYPES)
def test_integer_cast_to_enum_15738(dt: pl.DataType) -> None:
s = pl.Series([0, 1, 2], dtype=dt).cast(pl.Enum(["a", "b", "c"]))
assert s.to_list() == ["a", "b", "c"]
Expand Down
18 changes: 2 additions & 16 deletions py-polars/tests/unit/lazyframe/test_lazyframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PolarsInefficientMapWarning,
)
from polars.testing import assert_frame_equal, assert_series_equal
from tests.unit.conftest import FLOAT_DTYPES
from tests.unit.conftest import FLOAT_DTYPES, NUMERIC_DTYPES

if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
Expand Down Expand Up @@ -1334,21 +1334,7 @@ def test_compare_schema_between_lazy_and_eager_6904() -> None:


@pytest.mark.slow
@pytest.mark.parametrize(
"dtype",
[
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.Float32,
pl.Float64,
],
)
@pytest.mark.parametrize("dtype", NUMERIC_DTYPES)
@pytest.mark.parametrize(
"func",
[
Expand Down
13 changes: 2 additions & 11 deletions py-polars/tests/unit/operations/map/test_map_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import polars as pl
from polars.exceptions import PolarsInefficientMapWarning
from polars.testing import assert_frame_equal, assert_series_equal
from tests.unit.conftest import INTEGER_DTYPES

pytestmark = pytest.mark.filterwarnings(
"ignore::polars.exceptions.PolarsInefficientMapWarning"
Expand Down Expand Up @@ -129,18 +130,8 @@ def test_map_elements_list_any_value_fallback() -> None:


def test_map_elements_all_types() -> None:
dtypes = [
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
]
# test we don't panic
for dtype in dtypes:
for dtype in INTEGER_DTYPES:
pl.Series([1, 2, 3, 4, 5], dtype=dtype).map_elements(lambda x: x)


Expand Down
28 changes: 6 additions & 22 deletions py-polars/tests/unit/operations/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import polars as pl
from polars.testing import assert_frame_equal, assert_series_equal
from tests.unit.conftest import INTEGER_DTYPES


@pytest.mark.parametrize("op", ["and_", "or_"])
Expand Down Expand Up @@ -80,20 +81,7 @@ def trailing_ones(v: int | None) -> int | None:
None,
],
)
@pytest.mark.parametrize(
"dtype",
[
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Boolean,
],
)
@pytest.mark.parametrize("dtype", [*INTEGER_DTYPES, pl.Boolean])
@pytest.mark.skipif(sys.version_info < (3, 10), reason="bit_count introduced in 3.10")
@typing.no_type_check
def test_bit_counts(value: int, dtype: pl.DataType) -> None:
Expand All @@ -106,6 +94,8 @@ def test_bit_counts(value: int, dtype: pl.DataType) -> None:
bitsize = 32
elif "64" in str(dtype):
bitsize = 64
elif "128" in str(dtype):
bitsize = 128

if bitsize == 1 and value is not None:
value = value & 1 != 0
Expand Down Expand Up @@ -150,10 +140,7 @@ def test_bit_counts(value: int, dtype: pl.DataType) -> None:
)


@pytest.mark.parametrize(
"dtype",
[pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64],
)
@pytest.mark.parametrize("dtype", INTEGER_DTYPES)
def test_bit_aggregations(dtype: pl.DataType) -> None:
s = pl.Series("a", [0x74, 0x1C, 0x05], dtype)

Expand All @@ -175,10 +162,7 @@ def test_bit_aggregations(dtype: pl.DataType) -> None:
)


@pytest.mark.parametrize(
"dtype",
[pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64],
)
@pytest.mark.parametrize("dtype", INTEGER_DTYPES)
def test_bit_group_by(dtype: pl.DataType) -> None:
df = pl.DataFrame(
[
Expand Down
29 changes: 10 additions & 19 deletions py-polars/tests/unit/operations/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from polars.exceptions import ComputeError, InvalidOperationError
from polars.testing import assert_frame_equal
from polars.testing.asserts.series import assert_series_equal
from tests.unit.conftest import INTEGER_DTYPES

if TYPE_CHECKING:
from polars._typing import PolarsDataType, PythonDataType
Expand Down Expand Up @@ -560,21 +561,14 @@ def test_strict_cast_string(
@pytest.mark.parametrize(
"dtype_out",
[
(pl.UInt8),
(pl.Int8),
(pl.UInt16),
(pl.Int16),
(pl.UInt32),
(pl.Int32),
(pl.UInt64),
(pl.Int64),
(pl.Date),
(pl.Datetime),
(pl.Time),
(pl.Duration),
(pl.String),
(pl.Categorical),
(pl.Enum(["1", "2"])),
*INTEGER_DTYPES,
pl.Date,
pl.Datetime,
pl.Time,
pl.Duration,
pl.String,
pl.Categorical,
pl.Enum(["1", "2"]),
],
)
def test_cast_categorical_name_retention(
Expand Down Expand Up @@ -669,10 +663,7 @@ def test_all_null_cast_5826() -> None:
assert out.item() is None


@pytest.mark.parametrize(
"dtype",
[pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Int8, pl.Int16, pl.Int32, pl.Int64],
)
@pytest.mark.parametrize("dtype", INTEGER_DTYPES)
def test_bool_numeric_supertype(dtype: PolarsDataType) -> None:
df = pl.DataFrame({"v": [1, 2, 3, 4, 5, 6]})
result = df.select((pl.col("v") < 3).sum().cast(dtype) / pl.len())
Expand Down
17 changes: 2 additions & 15 deletions py-polars/tests/unit/operations/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import polars as pl
from polars.testing import assert_frame_equal
from tests.unit.conftest import NUMERIC_DTYPES

if TYPE_CHECKING:
from polars._typing import PolarsDataType, PolarsTemporalType
Expand Down Expand Up @@ -85,21 +86,7 @@ def test_interpolate_temporal_linear(
assert_frame_equal(result.collect(), expected)


@pytest.mark.parametrize(
"input_dtype",
[
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Float32,
pl.Float64,
],
)
@pytest.mark.parametrize("input_dtype", NUMERIC_DTYPES)
def test_interpolate_nearest(input_dtype: PolarsDataType) -> None:
df = pl.LazyFrame({"a": [1, None, 2, None, 3]}, schema={"a": input_dtype})
result = df.with_columns(pl.all().interpolate(method="nearest"))
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def test_raise_invalid_namespace() -> None:
(pl.UInt32, 0, 4294967295),
(pl.Int64, -9223372036854775808, 9223372036854775807),
(pl.UInt64, 0, 18446744073709551615),
(
pl.Int128,
-170141183460469231731687303715884105728,
170141183460469231731687303715884105727,
),
(pl.Float32, float("-inf"), float("inf")),
(pl.Float64, float("-inf"), float("inf")),
],
Expand Down
14 changes: 2 additions & 12 deletions py-polars/tests/unit/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import polars as pl
from polars.testing import assert_frame_equal
from tests.unit.conftest import NUMERIC_DTYPES


def test_sort_by_bools() -> None:
Expand Down Expand Up @@ -172,18 +173,7 @@ def test_group_by_agg_equals_zero_3535() -> None:


def test_dtype_concat_3735() -> None:
for dt in [
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
pl.Float32,
pl.Float64,
]:
for dt in NUMERIC_DTYPES:
d1 = pl.DataFrame([pl.Series("val", [1, 2], dtype=dt)])

d2 = pl.DataFrame([pl.Series("val", [3, 4], dtype=dt)])
Expand Down
23 changes: 3 additions & 20 deletions py-polars/tests/unit/test_row_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from polars.testing import assert_frame_equal, assert_series_equal
from polars.testing.parametric import dataframes, series
from polars.testing.parametric.strategies.dtype import dtypes
from tests.unit.conftest import FLOAT_DTYPES, INTEGER_DTYPES

if TYPE_CHECKING:
from polars._typing import PolarsDataType
Expand Down Expand Up @@ -78,19 +79,7 @@ def test_bool(field: tuple[bool, bool, bool]) -> None:
roundtrip_series_re([True, False], pl.Boolean, field)


@pytest.mark.parametrize(
"dtype",
[
pl.Int8,
pl.Int16,
pl.Int32,
pl.Int64,
pl.UInt8,
pl.UInt16,
pl.UInt32,
pl.UInt64,
],
)
@pytest.mark.parametrize("dtype", INTEGER_DTYPES)
@pytest.mark.parametrize("field", FIELD_COMBS)
def test_int(dtype: pl.DataType, field: tuple[bool, bool, bool]) -> None:
min = pl.select(x=dtype.min()).item() # type: ignore[attr-defined]
Expand All @@ -106,13 +95,7 @@ def test_int(dtype: pl.DataType, field: tuple[bool, bool, bool]) -> None:
roundtrip_series_re([min, 0, max], dtype, field)


@pytest.mark.parametrize(
"dtype",
[
pl.Float32,
pl.Float64,
],
)
@pytest.mark.parametrize("dtype", FLOAT_DTYPES)
@pytest.mark.parametrize("field", FIELD_COMBS)
def test_float(dtype: pl.DataType, field: tuple[bool, bool, bool]) -> None:
inf = float("inf")
Expand Down
Loading

0 comments on commit c9ba7bf

Please sign in to comment.