Skip to content

Commit 375a66e

Browse files
committed
Merge pull request #5780 from jreback/sparc_fix
TST: close sparc test failures
2 parents 4952858 + 9ed4f7d commit 375a66e

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

pandas/core/common.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ class AmbiguousIndexError(PandasError, KeyError):
4040

4141

4242
_POSSIBLY_CAST_DTYPES = set([np.dtype(t)
43-
for t in ['M8[ns]', 'm8[ns]', 'O', 'int8',
43+
for t in ['M8[ns]', '>M8[ns]', '<M8[ns]',
44+
'm8[ns]', '>m8[ns]', '<m8[ns]',
45+
'O', 'int8',
4446
'uint8', 'int16', 'uint16', 'int32',
4547
'uint32', 'int64', 'uint64']])
4648

4749
_NS_DTYPE = np.dtype('M8[ns]')
4850
_TD_DTYPE = np.dtype('m8[ns]')
4951
_INT64_DTYPE = np.dtype(np.int64)
50-
_DATELIKE_DTYPES = set([np.dtype(t) for t in ['M8[ns]', 'm8[ns]']])
52+
_DATELIKE_DTYPES = set([np.dtype(t) for t in ['M8[ns]', '<M8[ns]', '>M8[ns]',
53+
'm8[ns]', '<m8[ns]', '>m8[ns]']])
5154

5255

5356
# define abstract base classes to enable isinstance type checking on our
@@ -1572,11 +1575,17 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
15721575

15731576
# force the dtype if needed
15741577
if is_datetime64 and dtype != _NS_DTYPE:
1575-
raise TypeError(
1576-
"cannot convert datetimelike to dtype [%s]" % dtype)
1578+
if dtype.name == 'datetime64[ns]':
1579+
dtype = _NS_DTYPE
1580+
else:
1581+
raise TypeError(
1582+
"cannot convert datetimelike to dtype [%s]" % dtype)
15771583
elif is_timedelta64 and dtype != _TD_DTYPE:
1578-
raise TypeError(
1579-
"cannot convert timedeltalike to dtype [%s]" % dtype)
1584+
if dtype.name == 'timedelta64[ns]':
1585+
dtype = _TD_DTYPE
1586+
else:
1587+
raise TypeError(
1588+
"cannot convert timedeltalike to dtype [%s]" % dtype)
15801589

15811590
if np.isscalar(value):
15821591
if value == tslib.iNaT or isnull(value):

pandas/core/internals.py

+2
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,10 @@ def _try_operate(self, values):
12451245
def _try_coerce_result(self, result):
12461246
""" reverse of try_coerce_args / try_operate """
12471247
if isinstance(result, np.ndarray):
1248+
mask = isnull(result)
12481249
if result.dtype.kind in ['i', 'f', 'O']:
12491250
result = result.astype('m8[ns]')
1251+
result[mask] = tslib.iNaT
12501252
elif isinstance(result, np.integer):
12511253
result = np.timedelta64(result)
12521254
return result

pandas/io/tests/test_stata.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
from pandas.util.misc import is_little_endian
1515
from pandas import compat
1616

17+
def skip_if_not_little_endian():
18+
if not is_little_endian():
19+
raise nose.SkipTest("known failure of test on non-little endian")
20+
1721
class TestStata(tm.TestCase):
1822

1923
def setUp(self):
@@ -145,9 +149,7 @@ def test_read_dta4(self):
145149
tm.assert_frame_equal(parsed_13, expected)
146150

147151
def test_read_write_dta5(self):
148-
if not is_little_endian():
149-
raise nose.SkipTest("known failure of test_write_dta5 on "
150-
"non-little endian")
152+
skip_if_not_little_endian()
151153

152154
original = DataFrame([(np.nan, np.nan, np.nan, np.nan, np.nan)],
153155
columns=['float_miss', 'double_miss', 'byte_miss',
@@ -161,9 +163,7 @@ def test_read_write_dta5(self):
161163
original)
162164

163165
def test_write_dta6(self):
164-
if not is_little_endian():
165-
raise nose.SkipTest("known failure of test_write_dta6 on "
166-
"non-little endian")
166+
skip_if_not_little_endian()
167167

168168
original = self.read_csv(self.csv3)
169169
original.index.name = 'index'
@@ -193,9 +193,7 @@ def test_read_dta9(self):
193193
tm.assert_frame_equal(parsed, expected)
194194

195195
def test_read_write_dta10(self):
196-
if not is_little_endian():
197-
raise nose.SkipTest("known failure of test_write_dta10 on "
198-
"non-little endian")
196+
skip_if_not_little_endian()
199197

200198
original = DataFrame(data=[["string", "object", 1, 1.1,
201199
np.datetime64('2003-12-25')]],
@@ -232,6 +230,8 @@ def test_encoding(self):
232230
self.assert_(isinstance(result, unicode))
233231

234232
def test_read_write_dta11(self):
233+
skip_if_not_little_endian()
234+
235235
original = DataFrame([(1, 2, 3, 4)],
236236
columns=['good', compat.u('b\u00E4d'), '8number', 'astringwithmorethan32characters______'])
237237
formatted = DataFrame([(1, 2, 3, 4)],
@@ -248,6 +248,8 @@ def test_read_write_dta11(self):
248248
tm.assert_frame_equal(written_and_read_again.set_index('index'), formatted)
249249

250250
def test_read_write_dta12(self):
251+
skip_if_not_little_endian()
252+
251253
original = DataFrame([(1, 2, 3, 4)],
252254
columns=['astringwithmorethan32characters_1', 'astringwithmorethan32characters_2', '+', '-'])
253255
formatted = DataFrame([(1, 2, 3, 4)],

0 commit comments

Comments
 (0)