Skip to content
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

Bug: Many to Many relational keys converts to floats. #93

Open
hyzyla opened this issue Mar 5, 2018 · 4 comments
Open

Bug: Many to Many relational keys converts to floats. #93

hyzyla opened this issue Mar 5, 2018 · 4 comments

Comments

@hyzyla
Copy link

hyzyla commented Mar 5, 2018

I have model Status and Station, that have many to many relations.
Following command:

read_frame(Status.objects.values('id', 'stations__id'), verbose=False)

returns:

   id  stations__id
0   1           NaN
1   2           NaN
2   3           1.0
3   3           2.0
4   3           3.0
5   4           4.0
6   4           5.0
7   4           6.0

Keys must be integers, not floats. It seems like null converts all values in a column into floats.

@ckoerber
Copy link

Indeed the null entry seems to be the reason for the float conversion.

It might be possible to fix this by changing the many-to-many column datatype to "Int64".

See also the pandas docs about nullable integer data type.

@hyzyla
Copy link
Author

hyzyla commented Oct 23, 2019

@ckoerber, yes, I can convert. But for me, it seems strange that when the column doesn't have null, then it will have an integer type, and float when a column contains null values.
Does pandas series support null/none values for integer type?

@ckoerber
Copy link

@hyzyla, yes the "Int64" type supports integer and np.nan or None values (which I believe correspond to field null values)

E.g.,

> pd.Series([1, None])
0    1.0
1    NaN
dtype: float64

vs

> pd.Series([1, None], dtype="Int64")
0      1
1    NaN
dtype: Int64

This should be present in pandas version 0.24.0 regarding the above link.

@hyzyla
Copy link
Author

hyzyla commented Oct 23, 2019

Thanks, I will try make PR for fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants