-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: loc casting to object for multi block case when setting with list indexer #49161
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1898,16 +1898,20 @@ def _setitem_with_indexer_2d_value(self, indexer, value): | |
|
||
ilocs = self._ensure_iterable_column_indexer(indexer[1]) | ||
|
||
# GH#7551 Note that this coerces the dtype if we are mixed | ||
value = np.array(value, dtype=object) | ||
if not is_array_like(value): | ||
# cast lists to array | ||
value = np.array(value, dtype=object) | ||
if len(ilocs) != value.shape[1]: | ||
raise ValueError( | ||
"Must have equal len keys and value when setting with an ndarray" | ||
) | ||
|
||
for i, loc in enumerate(ilocs): | ||
# setting with a list, re-coerces | ||
self._setitem_single_column(loc, value[:, i].tolist(), pi) | ||
value_col = value[:, i] | ||
if is_object_dtype(value_col): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick value_col -> value_col.dtype There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
# try coerce values as good as possible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the wording here is pretty kludgy, maybe "casting to list so that we do type inference in setitem_single_column" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed, thx |
||
value_col = value_col.tolist() | ||
self._setitem_single_column(loc, value_col, pi) | ||
|
||
def _setitem_with_indexer_frame_value(self, indexer, value: DataFrame, name: str): | ||
ilocs = self._ensure_iterable_column_indexer(indexer[1]) | ||
|
@@ -2255,7 +2259,7 @@ def ravel(i): | |
ser_values = ser.reindex(obj.axes[0][indexer[0]], copy=True)._values | ||
|
||
# single indexer | ||
if len(indexer) > 1 and not multiindex_indexer: | ||
if len(indexer) > 1 and len(indexer[1]) > 1 and not multiindex_indexer: | ||
len_indexer = len(indexer[1]) | ||
ser_values = ( | ||
np.tile(ser_values, len_indexer).reshape(len_indexer, -1).T | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the GH reference here worth keeping somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think so, since we are avoiding this now