diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 945922b5f9ba8..05a26456374bd 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -1727,4 +1727,5 @@ Other - Compat with SciPy 0.19.0 for testing on ``.interpolate()`` (:issue:`15662`) - Compat for 32-bit platforms for ``.qcut/cut``; bins will now be ``int64`` dtype (:issue:`14866`) - Bug in interactions with ``Qt`` when a ``QtApplication`` already exists (:issue:`14372`) +- Bug in DataFrame constructor failing to handle dtypes with passed a Series with a falsey name (:issue:`16114`) - Avoid use of ``np.finfo()`` during ``import pandas`` removed to mitigate deadlock on Python GIL misuse (:issue:`14641`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b3da897b97e5c..983a6ef3e045a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -296,7 +296,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, if columns is None: columns = data_columns mgr = self._init_dict(data, index, columns, dtype=dtype) - elif getattr(data, 'name', None): + elif getattr(data, 'name', None) is not None: mgr = self._init_dict({data.name: data}, index, columns, dtype=dtype) else: diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 737d9f8e50477..f6cdb37a2477a 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1888,6 +1888,15 @@ def test_from_records_len0_with_columns(self): self.assertEqual(len(result), 0) self.assertEqual(result.index.name, 'foo') + def test_to_frame_with_falsey_names(self): + # GH 16114 + result = Series(name=0).to_frame().dtypes + expected = Series({0: np.float64}) + tm.assert_series_equal(result, expected) + + result = DataFrame(Series(name=0)).dtypes + tm.assert_series_equal(result, expected) + class TestDataFrameConstructorWithDatetimeTZ(tm.TestCase, TestData):