Skip to content

Commit 4ca4fca

Browse files
TomAugspurgerjreback
authored andcommitted
BUG: Compare names with None in DataFrame ctor
Closes #16114 Author: Tom Augspurger <[email protected]> Closes #16117 from TomAugspurger/int_dtypes and squashes the following commits: 7f7a32e [Tom Augspurger] DOC: Add a release note 0663098 [Tom Augspurger] BUG: Compare names with None in DataFrame ctor
1 parent 008e9ec commit 4ca4fca

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
296296
if columns is None:
297297
columns = data_columns
298298
mgr = self._init_dict(data, index, columns, dtype=dtype)
299-
elif getattr(data, 'name', None):
299+
elif getattr(data, 'name', None) is not None:
300300
mgr = self._init_dict({data.name: data}, index, columns,
301301
dtype=dtype)
302302
else:

pandas/tests/frame/test_constructors.py

+9
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,15 @@ def test_from_records_len0_with_columns(self):
18881888
self.assertEqual(len(result), 0)
18891889
self.assertEqual(result.index.name, 'foo')
18901890

1891+
def test_to_frame_with_falsey_names(self):
1892+
# GH 16114
1893+
result = Series(name=0).to_frame().dtypes
1894+
expected = Series({0: np.float64})
1895+
tm.assert_series_equal(result, expected)
1896+
1897+
result = DataFrame(Series(name=0)).dtypes
1898+
tm.assert_series_equal(result, expected)
1899+
18911900

18921901
class TestDataFrameConstructorWithDatetimeTZ(tm.TestCase, TestData):
18931902

0 commit comments

Comments
 (0)