-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: apply() fails on some value types #34529
Comments
hello i would like to look into this issue! |
@simondsmart thanks for the report. That's indeed an error that should not be seen by the user (and in 0.25 it was working) Now, although it should not raise an error, it's also not fully clear to me what you are trying to achieve. The column in the dataframe already has a @Veronur always welcome to take a look! |
@jorisvandenbossche the code came from a rather different context. We have a library that does decoding of a rather esoteric data type (ODB2, the pyodc library). It has an optional ability to offload to a (separate) C++ library that does the decoding much faster - but requires that we set up arrays with rather strict memory layout requirements to decode into. We then have to do a bit of ... coercion ... to get back to something appropriate in python land. The bug report was rather aggressively simplified to the simplest case I could make to trigger the same error. So it looks like something rather daft. Many thanks for your help! |
Ok so what i found out is this: the example you give is instead of using df.apply(lambda x: x.astype('object')) you do df.apply(lambda x: x.astype('|S')) it the command will run beacuse currently pandas is intepreting strings as an object itself but fo byteStrings it gets an array_interface https://numpy.org/devdocs/reference/arrays.interface.html#arrays-interface so thats why the dtypes were diferent. If this is unexpected behavour id like some guidelines on how to make a fix for it and if this is supposed to happen id be happy to make some test for it! |
Thanks for looking into this @Veronur. I'm also not sure the best way to handle it, but it'd be nice to fix the regression for the 1.1 release (in a few weeks) as long as we don't give up on other behaviors.. |
Alright i have done some more digging and i ma getting close to to source of the problem, so bar i found out that the dtype is changed from |S# to object on the Series generation for the dummy array on the " generic.NDFrame.init(self, data) " fuction call. There the values array is generated with object dtype instead of |S# as expected. |
Alright i found the problem and made a fix for it. The problem with on the pandas/core/dtypes/cast.py file. It was made on issue #21083 but since python3 "U" types and "S" types became different things |
The pull request is having some issues now with some tests that use the None type because thats what |
correction and test for issue-pandas-dev#34529
correction and test for issue-pandas-dev#34529 made the formating changes
correction and test for issue-pandas-dev#34529 made the formating changes fixing tests on issue-pandas-dev#34529
correction and test for issue-pandas-dev#34529 made the formating changes fixing tests on issue-pandas-dev#34529 add whats new entry on issue-pandas-dev#34539
correction and test for issue-pandas-dev#34529 made the formating changes fixing tests on issue-pandas-dev#34529 add whats new entry on issue-pandas-dev#34539 add whats new entry correction issue-pandas-dev#34539
correction and test for issue-pandas-dev#34529 made the formating changes fixing tests on issue-pandas-dev#34529 add whats new entry on issue-pandas-dev#34539 add whats new entry correction issue-pandas-dev#34539 whats new correction issue-pandas-dev#34539
We have some existing code that manipulates data that is decoded into numpy arrays (by a C powered backend). This code has stopped working.
I've tried to strip it down to a reduced case
This fails with an error inside an internal function of apply:
If we use a different dtype, then it works.
which gives the expected result
The text was updated successfully, but these errors were encountered: