Skip to content

Backport PR #47581 on branch 1.4.x (BUG: DataFrame.loc not aligning rhs df for single block case) #47984

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

Merged
merged 5 commits into from
Aug 8, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Aug 5, 2022

Backport PR #47581

cc @simonjayhawkins

WIll put up a pr for the whatsnew later

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check whether #47361 was a regression first as the merge conflicts here look like they are down to those changes.

yeah simpler to leave out the release note here. do a move on master, then just sync 1.4.4 release notes directly on 1.4.x (although we have a another backport on hold)

@simonjayhawkins
Copy link
Member

we need to check whether #47361 was a regression first

sorry, meant #47216

Comment on lines 4534 to 4535
elif is_dict_like(value):
return _reindex_for_setitem(Series(value), self.index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this includes the changes from #47361, so should backport that first (I think) so that we include test_setitem_aligning_dict_with_index in the backport also

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and move that release note too (and update the milestones etc)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but first need to confirm if that's also a regression (I can do that tomorrow)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not a regression unfortunately, did not work on 1.3.5 either

@simonjayhawkins simonjayhawkins added this to the 1.4.4 milestone Aug 5, 2022
@simonjayhawkins simonjayhawkins added Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version labels Aug 5, 2022
# or through loc single_block_path
if isinstance(value, DataFrame):
return _reindex_for_setitem(value, self.index)
elif isinstance(value, Series):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit weird now, but is closer to main than combining this two branches

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right so the comment # We should never get here with DataFrame value was not true?

the new comment refers to isetitem which is not on 1.4.x so slightly confusing.

it looks weird because could have just done if isinstance(value, (Series, DataFrame)): instead?

and the case of handling a dict-like value for the rhs was not working on 1.3.5 so we leaving that behavior unchanged here?

and slightly OT for the backport, on main we get a rogue warning?

FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  result.loc[:, "var"] = rhs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right so the comment # We should never get here with DataFrame value was not true?

Yes, this was incorrect

the new comment refers to isetitem which is not on 1.4.x so slightly confusing.

good point forgot about this. will remove

it looks weird because could have just done if isinstance(value, (Series, DataFrame)): instead?

wanted to keep it closer to main, but can combine

and the case of handling a dict-like value for the rhs was not working on 1.3.5 so we leaving that behavior unchanged here?

correct

Yeah the warning is a bit annoying. Intend to look into this soonish

@simonjayhawkins
Copy link
Member

OK if not a regression then not necessarily an issue as we can still do bug fixes in patch releases. don't merge yet, I'll look again tomorrow. If we go with the original commit in this PR we should probably do it as 2 separate backports.

@phofl
Copy link
Member Author

phofl commented Aug 5, 2022

Yep, if we do both then separate.

I would just do the regression here. It's close to 1.5 anyway. The change compared to main is not that big

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @phofl lgtm. The diff makes more sense now.

@simonjayhawkins simonjayhawkins merged commit 0ea10ff into pandas-dev:1.4.x Aug 8, 2022
@phofl phofl deleted the backport_47581 branch August 8, 2022 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants