Skip to content

Commit 271c0d8

Browse files
BUG: Dataframe constructor when given dict with None value
1 parent d98e982 commit 271c0d8

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v0.19.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bug Fixes
3232
~~~~~~~~~
3333

3434

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

3637

3738

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2915,8 +2915,8 @@ def create_from_value(value, index, dtype):
29152915

29162916
return subarr
29172917

2918-
# scalar like
2919-
if subarr.ndim == 0:
2918+
# scalar like, GH
2919+
if getattr(subarr, 'ndim', 0) == 0:
29202920
if isinstance(data, list): # pragma: no cover
29212921
subarr = np.array(data, dtype=object)
29222922
elif index is not None:

pandas/tests/frame/test_constructors.py

+6
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ def test_constructor_dict(self):
259259
frame = DataFrame({'A': [], 'B': []}, columns=['A', 'B'])
260260
self.assert_index_equal(frame.index, Index([], dtype=np.int64))
261261

262+
# GH 14381
263+
# Dict with None value
264+
frame_none = DataFrame(dict(a=None), index=[0])
265+
frame_nan = DataFrame(dict(a=[None]), index=[0])
266+
tm.assert_frame_equal(frame_none, frame_nan)
267+
262268
# GH10856
263269
# dict with scalar values should raise error, even if columns passed
264270
with tm.assertRaises(ValueError):

0 commit comments

Comments
 (0)