Skip to content

Commit

Permalink
MNT remove old fix for polars version 0.20 (#182)
Browse files Browse the repository at this point in the history
* MNT remove old fix for polars version 0.20

* TST skip test_compute_marginal for failing polars versions
  • Loading branch information
lorentzenchr authored Nov 4, 2024
1 parent 5f2a76f commit 2455e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/model_diagnostics/calibration/identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,14 @@ def compute_bias(
)
.sort("__priority", descending=True)
.head(n_bins)
)
# FIXME: When n_bins=0, the result should be an empty dataframe
# (0 rows and some columns). For some unknown reason as of
# polars 0.20.20, the following sort neglects the head(0) statement.
# Therefore, we place an explicit collect here. This should not be
# needed!
if n_bins == 0 or feature.null_count() >= 1:
df = df.collect().lazy()
df = df.sort(feature_name, descending=False)

df = df.select(
[
.sort(feature_name, descending=False)
.select(
pl.col(feature_name),
pl.col("bias_mean"),
pl.col("bias_count"),
pl.col("bias_weights"),
pl.col("bias_stderr"),
]
)
).collect()

# if is_categorical:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import polars as pl
import pytest
from packaging.version import Version
from polars.testing import assert_frame_equal, assert_series_equal
from scipy.special import stdtr
from scipy.stats import expectile, ttest_1samp
Expand Down Expand Up @@ -633,6 +634,11 @@ def test_compute_marginal(feature, f_grouped, bin_edges):
)
if bin_edges is not None:
df_expected = df_expected.hstack([bin_edges.alias("bin_edges")])

if Version("1.11.0") <= Version(pl.__version__) <= Version("1.12"):
# See https://github.com/pola-rs/polars/issues/19482
pytest.skip()

df_expected = df_expected.sort("feature")
assert_frame_equal(df_marginal, df_expected, check_exact=False)

Expand Down

0 comments on commit 2455e2d

Please sign in to comment.