We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents f5b3f8a + 4431101 commit ec34165Copy full SHA for ec34165
pandas/core/common.py
@@ -1038,7 +1038,8 @@ def _possibly_downcast_to_dtype(result, dtype):
1038
# try to upcast here
1039
elif inferred_type == 'floating':
1040
dtype = 'int64'
1041
- trans = lambda x: x.round()
+ if issubclass(result.dtype.type, np.number):
1042
+ trans = lambda x: x.round()
1043
1044
else:
1045
dtype = 'object'
pandas/tests/test_common.py
@@ -135,6 +135,20 @@ def test_downcast_conv():
135
expected = np.array([8, 8, 8, 8, 9])
136
assert (np.array_equal(result, expected))
137
138
+ # conversions
139
+
140
+ expected = np.array([1,2])
141
+ for dtype in [np.float64,object,np.int64]:
142
+ arr = np.array([1.0,2.0],dtype=dtype)
143
+ result = com._possibly_downcast_to_dtype(arr,'infer')
144
+ tm.assert_almost_equal(result, expected)
145
146
+ expected = np.array([1.0,2.0,np.nan])
147
+ for dtype in [np.float64,object]:
148
+ arr = np.array([1.0,2.0,np.nan],dtype=dtype)
149
150
151
152
def test_datetimeindex_from_empty_datetime64_array():
153
for unit in [ 'ms', 'us', 'ns' ]:
154
idx = DatetimeIndex(np.array([], dtype='datetime64[%s]' % unit))
0 commit comments