Skip to content

Commit fa21ad8

Browse files
committed
Merge pull request #7368 from cpcloud/fix-float-mixed
BUG/REG: fix float64index -> mixed float assignment
2 parents fa8a5ca + 3023280 commit fa21ad8

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

doc/source/v0.14.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,6 @@ Bug Fixes
120120
- Bug all ``StringMethods`` now work on empty Series (:issue:`7242`)
121121
- Fix delegation of `read_sql` to `read_sql_query` when query does not contain
122122
'select' (:issue:`7324`).
123+
- Bug where a string column name assignment to a ``DataFrame`` with a
124+
``Float64Index`` raised a ``TypeError`` during a call to ``np.isnan``
125+
(:issue:`7366`).

pandas/core/index.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -2060,11 +2060,14 @@ def __contains__(self, other):
20602060
return False
20612061

20622062
def get_loc(self, key):
2063-
if np.isnan(key):
2064-
try:
2065-
return self._nan_idxs.item()
2066-
except ValueError:
2067-
return self._nan_idxs
2063+
try:
2064+
if np.isnan(key):
2065+
try:
2066+
return self._nan_idxs.item()
2067+
except ValueError:
2068+
return self._nan_idxs
2069+
except (TypeError, NotImplementedError):
2070+
pass
20682071
return super(Float64Index, self).get_loc(key)
20692072

20702073
@property

pandas/tests/test_indexing.py

+10
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,16 @@ def f():
35613561

35623562
warnings.filterwarnings(action='ignore', category=FutureWarning)
35633563

3564+
def test_float_index_to_mixed(self):
3565+
df = DataFrame({0.0: np.random.rand(10),
3566+
1.0: np.random.rand(10)})
3567+
df['a'] = 10
3568+
tm.assert_frame_equal(DataFrame({0.0: df[0.0],
3569+
1.0: df[1.0],
3570+
'a': [10] * 10}),
3571+
df)
3572+
3573+
35643574
if __name__ == '__main__':
35653575
import nose
35663576
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)