diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 0a89806c899a4..3e06a705487df 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -120,3 +120,6 @@ Bug Fixes - Bug all ``StringMethods`` now work on empty Series (:issue:`7242`) - Fix delegation of `read_sql` to `read_sql_query` when query does not contain 'select' (:issue:`7324`). +- Bug where a string column name assignment to a ``DataFrame`` with a + ``Float64Index`` raised a ``TypeError`` during a call to ``np.isnan`` + (:issue:`7366`). diff --git a/pandas/core/index.py b/pandas/core/index.py index 9ccc2e694f92f..fbadd92c1329c 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -2060,11 +2060,14 @@ def __contains__(self, other): return False def get_loc(self, key): - if np.isnan(key): - try: - return self._nan_idxs.item() - except ValueError: - return self._nan_idxs + try: + if np.isnan(key): + try: + return self._nan_idxs.item() + except ValueError: + return self._nan_idxs + except (TypeError, NotImplementedError): + pass return super(Float64Index, self).get_loc(key) @property diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 062950cad43ed..96c67f2ff795c 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -3561,6 +3561,16 @@ def f(): warnings.filterwarnings(action='ignore', category=FutureWarning) + def test_float_index_to_mixed(self): + df = DataFrame({0.0: np.random.rand(10), + 1.0: np.random.rand(10)}) + df['a'] = 10 + tm.assert_frame_equal(DataFrame({0.0: df[0.0], + 1.0: df[1.0], + 'a': [10] * 10}), + df) + + if __name__ == '__main__': import nose nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],