From 06630982bdff248ac738b1822493cf319365c21f Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 24 Apr 2017 14:39:00 -0500 Subject: [PATCH 1/2] BUG: Compare names with None in DataFrame ctor Closes https://github.com/pandas-dev/pandas/issues/16114 --- pandas/core/frame.py | 2 +- pandas/tests/frame/test_constructors.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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): From 7f7a32e09ff242c555ae18a4d0b404c48b6d75da Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 24 Apr 2017 14:42:37 -0500 Subject: [PATCH 2/2] DOC: Add a release note (this was present in 0.19.2) --- doc/source/whatsnew/v0.20.0.txt | 1 + 1 file changed, 1 insertion(+) 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`)