Open ek-ex opened 3 months ago
hi @ek-ex
I can reproduce this.
the problem though is not the round
function but rather the display/formatting of f32 data.
pl.Config.set_fmt_str_lengths(100)
DATA = [1.0, 1.2, 1.3, 1.4, 1.5, 100.1, 100.2, 100.3, 100.4, 100.5]
pl.DataFrame(
{"f32": DATA, "f64": DATA},
schema={"f32": pl.Float32, "f64": pl.Float64},
).with_columns(
f32_decimals=pl.col("f32").map_elements(lambda x: f"{x:.20f}"),
f64_decimals=pl.col("f64").map_elements(lambda x: f"{x:.20f}"),
)
# shape: (10, 4)
# ┌────────────┬───────┬──────────────────────────┬──────────────────────────┐
# │ f32 ┆ f64 ┆ f32_decimals ┆ f64_decimals │
# │ --- ┆ --- ┆ --- ┆ --- │
# │ f32 ┆ f64 ┆ str ┆ str │
# ╞════════════╪═══════╪══════════════════════════╪══════════════════════════╡
# │ 1.0 ┆ 1.0 ┆ 1.00000000000000000000 ┆ 1.00000000000000000000 │
# │ 1.2 ┆ 1.2 ┆ 1.20000004768371582031 ┆ 1.19999999999999995559 │
# │ 1.3 ┆ 1.3 ┆ 1.29999995231628417969 ┆ 1.30000000000000004441 │
# │ 1.4 ┆ 1.4 ┆ 1.39999997615814208984 ┆ 1.39999999999999991118 │
# │ 1.5 ┆ 1.5 ┆ 1.50000000000000000000 ┆ 1.50000000000000000000 │
# │ 100.099998 ┆ 100.1 ┆ 100.09999847412109375000 ┆ 100.09999999999999431566 │
# │ 100.199997 ┆ 100.2 ┆ 100.19999694824218750000 ┆ 100.20000000000000284217 │
# │ 100.300003 ┆ 100.3 ┆ 100.30000305175781250000 ┆ 100.29999999999999715783 │
# │ 100.400002 ┆ 100.4 ┆ 100.40000152587890625000 ┆ 100.40000000000000568434 │
# │ 100.5 ┆ 100.5 ┆ 100.50000000000000000000 ┆ 100.50000000000000000000 │
# └────────────┴───────┴──────────────────────────┴──────────────────────────┘
💡 Important Concept
Decimal
typeI am not sure we need to take action on this. A DataFrame string representation shows you a concise information plot. If you require more control on how it is visualized you can set the float formatting options.
I am not sure if this is the same issue but this looks very inconsistent when i access the results
df = pl.DataFrame({"index": [1,2,3,4,5]})
df = df.with_columns(progress = pl.col("index") / pl.len())
df.get_column("progress").to_list()
This returns [0.2, 0.4, 0.6000000000000001, 0.8, 1.0]
Checks
Reproducible example
Log output
No response
Issue description
I'm using the round function in a column of floats with many decimals. However, sometimes the round is working as expected, sometimes it isnt.
Expected behavior
Round function consistently applied to all rows.
Installed versions