diff --git a/artistools/inputmodel/inputmodel_misc.py b/artistools/inputmodel/inputmodel_misc.py index d4e791823..fae044f97 100644 --- a/artistools/inputmodel/inputmodel_misc.py +++ b/artistools/inputmodel/inputmodel_misc.py @@ -426,6 +426,8 @@ def get_empty_3d_model( "headercommentlines": [], } + fncoordgrid = float(ncoordgrid) # fixes an issue with polars 0.20.23 https://github.com/pola-rs/polars/issues/15952 + dfmodel = ( pl.DataFrame( {"modelgridindex": range(ncoordgrid**3), "inputcellid": range(1, 1 + ncoordgrid**3)}, @@ -441,9 +443,9 @@ def get_empty_3d_model( ) .with_columns( [ - (-xmax + 2 * pl.col("n_x") * xmax / ncoordgrid).cast(pl.Float32).alias("pos_x_min"), - (-xmax + 2 * pl.col("n_y") * xmax / ncoordgrid).cast(pl.Float32).alias("pos_y_min"), - (-xmax + 2 * pl.col("n_z") * xmax / ncoordgrid).cast(pl.Float32).alias("pos_z_min"), + (-xmax + 2.0 * pl.col("n_x") * xmax / fncoordgrid).cast(pl.Float32).alias("pos_x_min"), + (-xmax + 2.0 * pl.col("n_y") * xmax / fncoordgrid).cast(pl.Float32).alias("pos_y_min"), + (-xmax + 2.0 * pl.col("n_z") * xmax / fncoordgrid).cast(pl.Float32).alias("pos_z_min"), ] ) ) diff --git a/artistools/packets/packets.py b/artistools/packets/packets.py index aeb31d4e3..a1e5839f7 100644 --- a/artistools/packets/packets.py +++ b/artistools/packets/packets.py @@ -944,7 +944,9 @@ def bin_and_sum( # Polars method dfcut = df.lazy().with_columns( - (pl.col(bincol).cut(breaks=bins, labels=[str(x) for x in range(-1, len(bins))])).alias(f"{bincol}_bin") + (pl.col(bincol).cut(breaks=bins, labels=[str(x) for x in range(-1, len(bins))])) + .alias(f"{bincol}_bin") + .cast(pl.Int32) ) aggs = [pl.col(col).sum().alias(col + "_sum") for col in sumcols] if sumcols is not None else [] @@ -952,7 +954,7 @@ def bin_and_sum( if getcounts: aggs.append(pl.col(bincol).count().alias("count")) - wlbins = dfcut.group_by(f"{bincol}_bin").agg(aggs).with_columns(pl.col(f"{bincol}_bin").cast(pl.Int32)) + wlbins = dfcut.group_by(f"{bincol}_bin").agg(aggs) # now we will include the empty bins return ( diff --git a/requirements.txt b/requirements.txt index 583603a9e..0319f7b7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ mypy>=1.10.0 numexpr>=2.10.0 numpy>=1.26.4 pandas[compression,parquet,pyarrow]>=2.2.2 -polars==0.20.22 +polars>=0.20.23 pre-commit>=3.7.0 pyarrow>=16.0.0 pynonthermal>=2024.2.17