Skip to content

BUG: Dataframe constructor when given dict with None value #14392

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
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/whatsnew/v0.19.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Bug Fixes
~~~~~~~~~


- Bug in ``pd.DataFrame`` where constructor fails when given dict with ``None`` value (:issue:`14381`)



Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2915,8 +2915,8 @@ def create_from_value(value, index, dtype):

return subarr

# scalar like
if subarr.ndim == 0:
# scalar like, GH
if getattr(subarr, 'ndim', 0) == 0:
if isinstance(data, list): # pragma: no cover
subarr = np.array(data, dtype=object)
elif index is not None:
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ def test_constructor_dict(self):
frame = DataFrame({'A': [], 'B': []}, columns=['A', 'B'])
self.assert_index_equal(frame.index, Index([], dtype=np.int64))

# GH 14381
# Dict with None value
frame_none = DataFrame(dict(a=None), index=[0])
frame_none_list = DataFrame(dict(a=[None]), index=[0])
tm.assert_equal(frame_none.get_value(0, 'a'), None)
tm.assert_equal(frame_none_list.get_value(0, 'a'), None)
tm.assert_frame_equal(frame_none, frame_none_list)

# GH10856
# dict with scalar values should raise error, even if columns passed
with tm.assertRaises(ValueError):
Expand Down