DEV Community

Patryk P
Patryk P

Posted on

(Im)mutability of polars DataFrame

Hey guys, there is one thing that I don't understand in polars. Everybody says that polars dataframes are immutable. However I can perform these operations without changing id of the object:

import polars as pl

my_df = pl.DataFrame({"a": [1, 2, 3], "b": [2, 3, 4]})
print(id(my_df))

my_df[0, "a"] = 10

print(my_df)
print(id(my_df))  # it's the same id
Enter fullscreen mode Exit fullscreen mode

The modified value is changed, however the id is the same. Why?

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay