You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that np.inf behaves differently than np.nan when using Pint Quanties in a Series/DataFrame. Finding and replacing seem to work transparently for np.nan, but np.inf can only be found when searching on the magnitudes of Pint Quantities. It would be convent if np.inf search/replaced worked like np.nan.
importnumpyasnpimportpandasaspdimportpint_pandasseries=pd.Series([np.nan, 6, np.inf])
pintSeries=pd.Series(series, dtype="pint[meter]")
print("\nOriginal Series:\n{0}".format(series))
print("Not a number check:", series.isna().sum())
print("Infinity check:", series.isin([np.inf]).sum())
series=series.replace(np.nan, 0)
series=series.replace(np.inf, 0)
print("\nSeries After Replacement:\n{0}".format(series))
print("\nOriginal Pint Series:\n{0}".format(pintSeries))
print("Not a number check succeeds:", pintSeries.isna().sum())
print("Standard infinity check fails:", pintSeries.isin([np.inf]).sum())
print("Infinity check on magnitudes succeeds:", pintSeries.pint.magnitude.isin([np.inf]).sum())
pintSeries=pintSeries.replace(np.nan, 0)
pintSeries=pintSeries.replace(np.inf, 0)
print("\nPint Series After Replacement:\n{0}".format(pintSeries))
Output:
Original Series:
0 NaN
1 6.0
2 inf
dtype: float64
Not a number check: 1
Infinity check: 1
Series After Replacement:
0 0.0
1 6.0
2 0.0
dtype: float64
Original Pint Series:
0 nan
1 6.0
2 inf
dtype: pint[meter]
Not a number check succeeds: 1
Standard infinity check fails: 0
Infinity check on magnitudes succeeds: 1
Pint Series After Replacement:
0 0.0
1 6.0
2 inf
dtype: pint[meter]
The text was updated successfully, but these errors were encountered:
It seems that
np.inf
behaves differently thannp.nan
when using Pint Quanties in a Series/DataFrame. Finding and replacing seem to work transparently fornp.nan
, butnp.inf
can only be found when searching on the magnitudes of Pint Quantities. It would be convent ifnp.inf
search/replaced worked likenp.nan
.Output:
The text was updated successfully, but these errors were encountered: