-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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/API: np.array([0, max_uint64]) has float64 dtype #19146
Comments
This is the downside of value based type inference of Python scalars. The zero is converted as signed, umax as unsigned. Then int64 plus uint64 -> float.
It isn't a bug, but definitely a wart. The best option when mixing unsigned and signed is to specify the dtype. EDIT: The way it works is that first conversion to signed is tried. If it fails, then conversion to unsigned is tried. |
can you point me to the relevant part of the code? context: im trying to make pandas inference/constructors do fewer passes |
Heh, I saw it once upon a time . . . There is similar code in three files: convert.c, scalarapi.c, and abstractdtypes.c. The repetition with some slight differences is unsettling. The last is probably what you are looking for.
The topic of value based conversion has been discussed as part of the new dtype work, @seberg might have more to say. |
Hmm, the last one should be the important one, yeah. There are two things to note here:
I.e. Future: My opinion is currently:
|
Do you mean you wouldn't do any inference in
Is a "best lossless" option on the table? (basically what clean_index_list described below aims for)
Poor wording on my part. I was actually asking about the part of the code that iterates over a not-yet-ndarray sequence to infer a dtype as part of the constructor. This would correspond to some combination of pd._libs' lib.infer_dtype and lib.maybe_convert_objects. The kind of pattern that im looking to avoid is in e.g. lib.clean_index_list where we do
infer_dtype does a pass through the array, then np.asarray is N-pass for N of I'm guessing 1 or 2, then the This seems like it should be doable in way fewer passes. |
Sorry, "value-based promotion" is not currently used for EDIT: So there will be no change here, inference of course happens, the question is how smart it is. The different integers being used when integers are large may go away though.
Some thoughts below, but maybe we should chat about this a bit? I think that pandas could leverage NumPy in principle, and that may well be worth the trouble. Although, I am a bit worried that it will also be a bit of a hack. On the other hand, I am not sure how well pandas could currently deal with NumPy user DType, and this might go a long way to that? A correct "best" lossless for signed or unsigned integers seems pretty tough (but I guess you do not need that?). Also the current NumPy implementation inside of Now for pandas? Even in the above
the problem is, that if you only have python floats, you get a float16 result ;). (The smaller problem is, that I am not sure I have implemented enough of casting yet to do the above.) For you, even that can't possibly be enough. You would need to track the current state in form of a That feels hackish, but to be honest, should work just fine. All we need to ensure is that an error is raised when its used (we need that anyway probably). And a way to convert that instance to the actual one that can be attached to the NumPy array. In theory, that could be a method that is automatically called, i.e. |
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail pandas/tests/window/test_rolling.py also gets an i386 xfail for rounding error that may be x87 excess precision Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
We test on more architectures, so upstream's xfails are not always correct everywhere. On those known to fail: arm64 xfail -> all non-x86 xfail x86 or unconditional strict xfail -> unconditional nonstrict xfail Author: Rebecca N. Palmer <rebecca_palmer@zoho.com> Bug: pandas-dev/pandas#38921, pandas-dev/pandas#38798, pandas-dev/pandas#41740, numpy/numpy#19146 Forwarded: no Gbp-Pq: Name fix_overly_arch_specific_xfails.patch
I expected to get uint64
There seems to be something special going on inference-wise around the int64 bound:
The text was updated successfully, but these errors were encountered: