Skip to content

WIP: BUG: Setting DataFrame values via iloc aligns when arguments are lists #33949

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

Closed
wants to merge 6 commits into from

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented May 2, 2020

This PR currently fails two tests on Windows due to int32 vs int64, but I cant' duplicate on my machine.

pandas\tests\indexing\test_indexing.py:588
test_astype_assignment

df = df_orig.copy()
df.iloc[:, 0:2] = df.iloc[:, 0:2].astype(np.int64)
expected = DataFrame(
    [[1, 2, "3", ".4", 5, 6.0, "foo"]], columns=list("ABCDEFG")
)
>       tm.assert_frame_equal(df, expected)
E       AssertionError: Attributes of DataFrame.iloc[:, 0] (column name="A") are different
E       
E       Attribute "dtype" are different
E       [left]:  int32
E       [right]: int64

Within these test, the change made causes the setting in iloc to be done here:

pandas/pandas/core/indexing.py

Lines 1722 to 1724 in c6ad13d

for i, loc in enumerate(ilocs):
# setting with a list, re-coerces
isetter(loc, value[:, i].tolist())

as opposed to the usual path here:

pandas/pandas/core/indexing.py

Lines 1695 to 1705 in c6ad13d

for loc in ilocs:
item = item_labels[loc]
if item in value:
sub_indexer[info_axis] = item
v = self._align_series(
tuple(sub_indexer), value[item], multiindex_indexer
)
else:
v = np.nan
isetter(loc, v)

My best guess is that this is a bug in the former path that is being uncovered by this change, but I am not sure how to fix. Any suggestions or help is much appreciated.

@rhshadrach rhshadrach closed this May 4, 2020
@rhshadrach rhshadrach reopened this May 10, 2020
@rhshadrach rhshadrach marked this pull request as draft May 10, 2020 18:35
@rhshadrach rhshadrach changed the title BUG: Setting DataFrame values via iloc aligns when arguments are lists WIP: BUG: Setting DataFrame values via iloc aligns when arguments are lists May 10, 2020
@rhshadrach rhshadrach marked this pull request as ready for review May 15, 2020 22:56
@rhshadrach rhshadrach changed the title WIP: BUG: Setting DataFrame values via iloc aligns when arguments are lists BUG: Setting DataFrame values via iloc aligns when arguments are lists May 15, 2020
@rhshadrach rhshadrach marked this pull request as draft May 16, 2020 14:38
@rhshadrach rhshadrach changed the title BUG: Setting DataFrame values via iloc aligns when arguments are lists WIP: BUG: Setting DataFrame values via iloc aligns when arguments are lists May 16, 2020
@rhshadrach
Copy link
Member Author

Needs #34217 to be addressed first. Closing to take off the queue.

@rhshadrach rhshadrach closed this May 25, 2020
@rhshadrach rhshadrach deleted the iloc_alignment branch October 11, 2020 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replacing multiple columns (or just one) with iloc does not work
1 participant