Skip to content

BUG: Indexing bugs with reordered indexes (GH6252, GH6254) #6256

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 1 commit into from
Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Bug Fixes

- Bug in version string gen. for dev versions with shallow clones / install from tarball (:issue:`6127`)
- Inconsistent tz parsing Timestamp/to_datetime for current year (:issue:`5958`)
- Indexing bugs with reordered indexes (:issue:`6252`, :issue:`6254`)

pandas 0.13.1
-------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ def setitem(self, indexer, value):
# if we are an exact match (ex-broadcasting),
# then use the resultant dtype
elif len(arr_value.shape) and arr_value.shape[0] == values.shape[0] and np.prod(arr_value.shape) == np.prod(values.shape):
values = arr_value.reshape(values.shape)
values[indexer] = value
values = values.astype(arr_value.dtype)

# set
else:
Expand Down
26 changes: 26 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,32 @@ def test_loc_setitem_frame(self):
result = df.ix[:,1:]
assert_frame_equal(result, expected)

# GH 6254
# setting issue
df = DataFrame(index=[3, 5, 4], columns=['A'])
df.loc[[4, 3, 5], 'A'] = [1, 2, 3]
expected = DataFrame(dict(A = Series([1,2,3],index=[4, 3, 5]))).reindex(index=[3,5,4])
assert_frame_equal(df, expected)

# GH 6252
# setting with an empty frame
keys1 = ['@' + str(i) for i in range(5)]
val1 = np.arange(5)

keys2 = ['@' + str(i) for i in range(4)]
val2 = np.arange(4)

index = list(set(keys1).union(keys2))
df = DataFrame(index = index)
df['A'] = nan
df.loc[keys1, 'A'] = val1

df['B'] = nan
df.loc[keys2, 'B'] = val2

expected = DataFrame(dict(A = Series(val1,index=keys1), B = Series(val2,index=keys2))).reindex(index=index)
assert_frame_equal(df, expected)

def test_loc_setitem_frame_multiples(self):

# multiple setting
Expand Down