-
Notifications
You must be signed in to change notification settings - Fork 192
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
Float no longer supports Inf #2412
Comments
Good question - probably it was just cautionary? @dev-zero do you remember the discussion about this? |
For what it's worth, hashing still seems to work in my temporary branch where I removed these checks. |
The problem is that JSON does not allow Inf or NaN in floats. See also the discussion here: https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
And since `clean_value` is applied on nested dicts stored as JSON in the DB I made it more restrictive.
If this must be supported I'd probably split the function and provide separate implementations for attributes stored directly in the DB as their native datatype (and only use a subset of the checks) and those stored as JSON.
…On 25 January 2019 09:53:26 CET, Dominik Gresch ***@***.***> wrote:
For what it's worth, hashing still seems to work in my temporary branch
where I removed these checks.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2412 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Ok, I see. If it's just dict (and list?) which have this issue we could just add a flag (like ``restrict_to_json``) which is just set to ``True`` the first time the ``clean_value`` goes through the recursive dict (and list?) comprehension.
Or is that too implicit a solution?
|
Since this will not be a breaking change as at worst more will be allowed, this is postponed to after |
I have recently had a problem with this, trying to import StructureData with NaN values. Looking around, I found a partial solution for the -Inf and Inf values, in the form of using the values -2e308 and 2e308, respectively. However, this still leaves an easy fix for NaN. |
Looking at this again, I don't completely understand what the issue is with JSON. Does Python maybe add some magic? The following works: In [1]: import json
In [2]: json.loads(json.dumps(float('inf')))
Out[2]: inf
In [3]: json.loads(json.dumps(float('nan')))
Out[3]: nan |
Ah indeed, the python |
So the question is this: Do we need to be strictly standard-compliant, or is the Python implementation the only one that will ever see our JSONs? |
We don't just rely on being able to dump to file though. Both database backends now use JSONB fields for the attributes and extras. I don't know for sure but maybe Postgres' implementation respects the JSON spec strictly. Try to store and attribute with |
even the value of |
Ah, I see.. this is a more recent change, right? As far as I can remember, when we initially discussed this I could "fix" What's the rationale for not storing it as a |
Because all data properties are stored as attributes. It used to be possible because in the old EAV schema (for Django) we did have float fields for float values. However, now the attributes are just stored in a single JSONB field. |
Makes sense - that's probably also better for consistency across DB backends. Do you have any other ideas for how to solve this issue? Or should we close it because it's not likely to be implemented any time soon? |
We could take inspiration from the python JSON implementation, and just auto-convert |
We can do conversion from those values to floats when storing if we don't care about comparison directly in the DB and type mismatch is not a problem. Probably, could be a solution with #3415 (note however that the query builder comparison would be the one for Also, what I would be also in general against is to infer from a string if it used to be a |
I'm not sure I completely understand the first point -- is it that the QueryBuilder (any maybe other things) look directly at the Regarding the second point, to be clear: This suggestion would be for the |
This also wouldn't solve #3415, since there it's an attribute of a different class. |
Correct, this is for efficiency reasons (delegating the query to the DB and not fetching all data first in python to run
I see - for the |
I think this makes it a bad idea to do some magic in the Unless there are other suggestions, I'd vote to close this issue as "wontfix". |
I agree, so will close it for now |
I'm reopening this because there is still a remaining issue: Since previous versions of AiiDA supported NaN / Inf, they can be in existing exports -- these break when trying to import on a new AiiDA instance. I'm also not sure if a migration path exists. |
Yeah no, I'll make a separate issue. |
(decided to open a separate issue instead of discussing on the merged PR)
In #2129, an error is raised when a Float is either nan or inf. The reasoning is that the
numeric
type of postgres doesn't support these special values. However, as far as I can tell Float is stored as a postgresfloat
, notnumeric
. I have used Inf in particular extensively without any issues in previous versions.Is there an error which led to the change in #2129, or was that just cautionary?
The text was updated successfully, but these errors were encountered: