Ancestors

Toot

Written by Thomas Arildsen on 2025-01-24 at 09:31

How do I correctly apply Pandas' 'infer_objects' function?

I try the following example in Pandas 2.2.3:

outage_mask = pd.Series(([True]*5 + [False]*5)*5, index=pd.date_range("2025-01-01", freq="1h", periods=50))
[ts for ts in outage_mask.loc[outage_mask.diff().fillna(False)].index]

This gives me a warning about downcasting object dtype arrays on 'fillna'. I cannot figure out how to apply the suggested 'infer_objects' correctly 🤔

https://stackoverflow.com/q/79383833/865169

=> More informations about this toot | More toots from arildsen@fosstodon.org

Descendants

Written by Thomas Arildsen on 2025-01-24 at 10:19

This answer on SO was helpful: https://stackoverflow.com/a/79383870/865169

Use convert_dtypes on the output of diff. This converts the Series to Pandas boolean, which is nullable and can contain the NaNs - problem solved.

It does not tell me how to correctly use infer_objects, but luckily I will not have to deal with that for now.

=> More informations about this toot | More toots from arildsen@fosstodon.org

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113882634720895929
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
252.727731 milliseconds
Gemini-to-HTML Time
0.969282 milliseconds

This content has been proxied by September (3851b).