Skip to content

Commit

Permalink
BUG: Allow overwriting object columns with EAs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Mar 30, 2018
1 parent c4b4a81 commit 3077a10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,10 @@ def should_store(self, value):
return not (issubclass(value.dtype.type,
(np.integer, np.floating, np.complexfloating,
np.datetime64, np.bool_)) or
is_extension_type(value))
# TODO(ExtensionArray): remove is_extension_type
# when all extension arrays have been ported.
is_extension_type(value) or
is_extension_array_dtype(value))

def replace(self, to_replace, value, inplace=False, filter=None,
regex=False, convert=True, mgr=None):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/base/reshaping.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ def test_set_frame_expand_extension_with_regular(self, data):
df['B'] = [1] * len(data)
expected = pd.DataFrame({"A": data, "B": [1] * len(data)})
self.assert_frame_equal(df, expected)

def test_set_frame_overwrite_object(self, data):
# https://github.com/pandas-dev/pandas/issues/20555
df = pd.DataFrame({"A": [1] * len(data)}, dtype=object)
df['A'] = data
assert df.dtypes['A'] == data.dtype

0 comments on commit 3077a10

Please sign in to comment.