Pandas pivot table fill_value parameter throws warning

Hi Everyone,

I have a pandas dataframe with set of columns and rows and using pivot table function creating a table out of it. I am setting fill_value parameter to ‘NULL’ to replace NAN with NUL values.
This piece of code does not throws any errors/warning in older version, but for pandas 2.2.2 version it throws below warning

Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True)

I have gone through some blogs and documentation but could not find out a proper page where it explains the reason why it throws this warning and fix to implement it.

As per suggestion in warngin, setting result.infer_objects(copy=False) did not work in my case, it still throws error.
Setting “pd.set_option(‘future.no_silent_downcasting’, True)” property stop showing this warning and I do not see any difference in output data as well.However I do not want to implement this until I have a proper understanding of what it does and what is the good solution to avid getting this warning.

Point to note here, removing fill_value parameter does not show this warning.

Can anyone please help to understand on this issue and fix for this?

What are the column dtypes (of the resulting pivot table) when you don’t specify the fill_value parameter? My suspicion is that they are floats, and so when you are specifying a string as the fill value, it would have to downcast to object dtype (leading to that message)