-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Regression in casting Series to DataFrame with .name='foo' and columns=['bar'] #7893
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
it's not documented as this is how it used to work quite a while ago use to_frame() |
Ok, thanks. It seems like this is a regression, unless this is considered deprecated. The above does not occur on 0.8.0 (when the code that hit this was written) or 0.12.0 but does for 0.13.0, so probably showed up as part of the internal rewrite. |
it might have slipped thru because wasn't tested (we actually have an amazing number of constructor tests) but it is pretty consistent in that the columns/index that are passed in act as reindexers that said the boat has sailed in this |
Here's my answer to the same question: http://stackoverflow.com/questions/21984862/creating-pandas-dataframe-and-renaming-change-0-10-0-to-0-13-1 If you'd like to put up a couple of tests for the current behavior would be great. |
@jreback Thanks for the pointer, I'll put together some tests over the weekend. |
@qwhelan ? |
xref #13421 with a
MultiIndex
as the columnsHi,
I encountered an edge case in DataFrame initialization with something like the following:
This happens in both 0.14.1 and 0.13.1, but this isn't really a bug as the docs exclude
Series
as a valid type fordata=
. That being said, this casting appears to work whenever.name
isNone
or when.name
equals what's passed tocolumns=
, so failure in this particular case is rather surprising.The mechanism appears to be:
DataFrame.__init__
upgrades.name
to the column name, if it is notNone
columns=
, resulting in an empty data set when the two differ.Series
is directly passed asdata=
. I can't get this to occur with[Series, ...]
or a dict ofSeries
.The options I see are (in order of my personal preference):
Series
, so no ambiguity)Series
being passed asdata=
.I don't see just documenting this behavior as being viable, as this edge case effectively leads to data loss.
The text was updated successfully, but these errors were encountered: