Skip to content

Commit 60a335e

Browse files
BUG: Dataframe constructor when given dict with None value (pandas-dev#14392)
1 parent b088112 commit 60a335e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.19.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bug Fixes
4141
- Bug in localizing an ambiguous timezone when a boolean is passed (:issue:`14402`)
4242
- Bug in ``TimedeltaIndex`` addition with a Datetime-like object where addition overflow in the negative direction was not being caught (:issue:`14068`, :issue:`14453`)
4343

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

4546

4647
- Bug in string indexing against data with ``object`` ``Index`` may raise ``AttributeError`` (:issue:`14424`)

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

+8
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ 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_none_list = DataFrame(dict(a=[None]), index=[0])
266+
tm.assert_equal(frame_none.get_value(0, 'a'), None)
267+
tm.assert_equal(frame_none_list.get_value(0, 'a'), None)
268+
tm.assert_frame_equal(frame_none, frame_none_list)
269+
262270
# GH10856
263271
# dict with scalar values should raise error, even if columns passed
264272
with tm.assertRaises(ValueError):

0 commit comments

Comments
 (0)