-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: PeriodIndex construction fails (or produces erroneous result) with memoryview as input. #13120
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
Comments
I suppose. You are much better off just doing |
note that |
We prob don't handle construction for Series/DataFrame with a memory buffer either. |
This is what we're currently doing (and what we'll probably continue to do for a while since we support older versions of pandas).
Yep, I assumed as much. What would you think about making public versions of some of the Pandas object constructors that accept limited, specific arguments and don't do any coercion? We frequently have the problem in Zipline that we have an object of a well-known type and we want to construct an Index/Series/DataFrame without incurring the extra overhead of Pandas having to infer the type of our input. |
@ssanderson not sure what you mean. The inference is generally very light so you shouldn't incur costs with anything. If you have a specific example I can look. |
Would the preferred behavior here be to coerce to |
The case that comes to mind offhand is something like |
@ssanderson no you could certainly add it as a clause somewhere here: https://github.com/pydata/pandas/blob/master/pandas/indexes/base.py#L124 easy enough to add a:
though better to put in the if/else's if possible (as it reduces the checks needed) e.g. right before the scalar check.
|
btw
|
TIL |
@ssanderson this is what all of the read-sql type things do (and pytables as well), these are row-structured arrays essentially. |
FWIW this works in master for DatetimeIndex and TimedeltaIndex (though not for PeriodIndex):
|
Only fails with
|
Actually this fully works for a PeriodIndex. Could all use a test
|
Code Sample, a copy-pastable example if possible
First noted in discussion here: https://github.com/quantopian/zipline/pull/1190/files/fe5a2a888a498d838c3cc43de2c33ac08b20d2a7#r62506342. This most often matters when passing a value typed in Cython as something like
int64_t[:]
.Simple repro cases:
DatetimeIndex construction fails (looks like trying to parse strings?), and vanilla Index construction returns an array of unicode strings.
Expected Output
I'd expect this to either error immediately or provide the same result as coercing the provided memoryview into a numpy array.
output of
pd.show_versions()
cc @jbredeche
The text was updated successfully, but these errors were encountered: