-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer values in pmb.df
become float when reading a pyMBE dataframe from file
#102
Comments
Yes! I will try to solve it |
@pm-blanco A quick update I have partially solved the issue changing:
for:
However, it changes the nan values from |
Hi! @jngrad We would like your opinion on this issue. In the previous comment I mentioned the solution I found for this issue, however, we still have the problem with We were talking with @pm-blanco to change in pyMBE all the functions that have |
That's really tricky. According to chapter Working with missing data, Here is a MWE: >>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame(data={"time": [1., 2., pd.NaT], "pos": [1.5, 2.5, 0.]})
>>> df
time pos
0 1.0 1.5
1 2.0 2.5
2 NaT 0.0
>>> (0. / df["pos"]) # generates np.nan
0 0.0
1 0.0
2 NaN
Name: pos, dtype: float64
>>> np.isnan(0. / df["pos"]) # works as expected
0 False
1 False
2 True
Name: pos, dtype: bool
>>> (0. / df["time"]) # generates NaN of type object
0 0.0
1 0.0
2 NaN
Name: time, dtype: object
>>> (0. / df["time"]).to_numpy().dtype # not convertible to numpy array of float64
dtype('O')
>>> np.isnan(np.nan)
True
>>> np.isnan(pd.NA) # doesn't work
<NA>
>>> pd.isna(pd.NA)
True
>>> pd.isna(np.nan) # always works
True
>>> pd.Series([1., np.inf, np.nan, pd.NA]).isnull() # np.nan decays to NULL
0 False
1 False
2 True
3 True
dtype: bool
>>> 1 / np.array([0., 1.]) # warning the first time
<stdin>:1: RuntimeWarning: divide by zero encountered in divide
array([inf, 1.])
>>> 1 / np.array([0., 1.]) # no warning the second time
array([inf, 1.])
>>> (0. / pd.Series([0., 1.])) # yields NaN
0 NaN
1 0.0
dtype: float64
>>> (0. / pd.Series([0., 1., pd.NaT])) # doesn't run because pd.NaT changes series type
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero I would say that |
Thank you for your insight @jngrad! This is indeed a very tricky issue indeed and not solution seems to be completely satisfying. At the moment, it seems that defaulting to |
I agree. We can link to the relevant chapter in the Pandas user manual, but should explicitly mention that |
Thanks @jngrad for your feedback about this issue. Perfect, then I will make the change to |
This becomes an issue when restarting simulations that have been set up with pyMBE since it breaks the setup of the reaction methods, which cannot be checkpointed with the current funtionalities in ESPResSo.
Here a minimal working example that shows this issue:
@paobtorres do you want to take care of solving this?
The text was updated successfully, but these errors were encountered: