Skip to content

Commit

Permalink
Fix for polars 0.20.23
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Apr 29, 2024
1 parent 29384d1 commit 04b49ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions artistools/inputmodel/inputmodel_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand All @@ -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"),
]
)
)
Expand Down
6 changes: 4 additions & 2 deletions artistools/packets/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,15 +944,17 @@ 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 []

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 (
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04b49ed

Please sign in to comment.