Skip to content

Commit

Permalink
REGR: Loc.setitem with enlargement raises for nested data (#48619)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Sep 18, 2022
1 parent f088f61 commit 64e042e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pandas/core/indexing.py
Expand Up @@ -2102,7 +2102,9 @@ def _setitem_with_indexer_missing(self, indexer, value):
return self._setitem_with_indexer(new_indexer, value, "loc")

# this preserves dtype of the value and of the object
if is_valid_na_for_dtype(value, self.obj.dtype):
if not is_scalar(value):
new_dtype = None
elif is_valid_na_for_dtype(value, self.obj.dtype):
value = na_value_for_dtype(self.obj.dtype, compat=False)
new_dtype = maybe_promote(self.obj.dtype, value)[0]
elif isna(value):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/indexing/test_indexing.py
Expand Up @@ -358,6 +358,15 @@ def test_loc_boolean_indexer_miss_matching_index():
ser.loc[indexer]


def test_loc_setitem_nested_data_enlargement():
# GH#48614
df = DataFrame({"a": [1]})
ser = Series({"label": df})
ser.loc["new_label"] = df
expected = Series({"label": df, "new_label": df})
tm.assert_series_equal(ser, expected)


class TestDeprecatedIndexers:
@pytest.mark.parametrize("key", [{1}, {1: 1}])
def test_getitem_dict_and_set_deprecated(self, key):
Expand Down

0 comments on commit 64e042e

Please sign in to comment.