Skip to content

Commit

Permalink
remove unneeded expensive assert (#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 6, 2022
1 parent 13645d4 commit 14cbeab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
7 changes: 3 additions & 4 deletions polars/polars-core/src/series/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ impl<'a> UnstableSeries<'a> {
}

/// Creates a new `[UnsafeSeries]`
/// # Panics
/// panics if `inner_chunk` is not from `Series`.
pub fn new_with_chunk(series: &'a Series, inner_chunk: &ArrayRef) -> Self {
assert_eq!(series.chunks()[0].as_ref(), inner_chunk.as_ref());
/// # Safety
/// Inner chunks must be from `Series` otherwise the dtype may be incorrect and lead to UB.
pub(crate) unsafe fn new_with_chunk(series: &'a Series, inner_chunk: &ArrayRef) -> Self {
UnstableSeries {
container: series,
inner: NonNull::new(inner_chunk as *const ArrayRef as *mut ArrayRef).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/apply/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::Wrap;
use polars::chunked_array::builder::get_list_builder;
use polars::prelude::*;
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyCFunction, PyDict, PyFloat, PyInt, PyList, PyString, PyTuple};
use pyo3::types::{PyBool, PyCFunction, PyDict, PyFloat, PyList, PyString, PyTuple};

/// Find the output type and dispatch to that implementation.
fn infer_and_finish<'a, A: ApplyLambda<'a>>(
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import io

import numpy as np
import pytest

Expand Down Expand Up @@ -35,3 +37,10 @@ def test_error_on_invalid_by_in_asof_join() -> None:
df2 = df1.with_column(pl.col("a").cast(pl.Categorical))
with pytest.raises(pl.ComputeError):
df1.join_asof(df2, on="b", by=["a", "c"])


def test_not_found_error() -> None:
csv = "a,b,c\n2,1,1"
df = pl.read_csv(io.StringIO(csv))
with pytest.raises(pl.NotFoundError):
df.select("d")
12 changes: 0 additions & 12 deletions py-polars/tests/test_fallible.py

This file was deleted.

18 changes: 18 additions & 0 deletions py-polars/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,21 @@ def test_arange_no_rows() -> None:
df = pl.DataFrame(dict(x=[]))
out = df.with_column(pl.arange(0, pl.count()).over("x")) # type: ignore
assert out.frame_equal(pl.DataFrame({"x": [], "literal": []}))


def test_no_panic_on_nan_3067() -> None:
df = pl.DataFrame(
{
"group": ["a", "a", "a", "b", "b", "b"],
"total": [1.0, 2, 3, 4, 5, np.NaN],
}
)

df.select([pl.col("total").shift().over("group")])["total"].to_list() == [
None,
1.0,
2.0,
None,
4.0,
5.0,
]

0 comments on commit 14cbeab

Please sign in to comment.