From e18da0efe3401b51b51cbce6fb6df365ca9f15cd Mon Sep 17 00:00:00 2001 From: jreback Date: Fri, 27 Dec 2013 12:54:44 -0500 Subject: [PATCH 1/2] TST: closes (GH5778), failing tests on non-little endian for stata (sparc) --- pandas/io/tests/test_stata.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pandas/io/tests/test_stata.py b/pandas/io/tests/test_stata.py index f75cf7ebb18d1..5a842adb561b1 100644 --- a/pandas/io/tests/test_stata.py +++ b/pandas/io/tests/test_stata.py @@ -14,6 +14,10 @@ from pandas.util.misc import is_little_endian from pandas import compat +def skip_if_not_little_endian(): + if not is_little_endian(): + raise nose.SkipTest("known failure of test on non-little endian") + class TestStata(tm.TestCase): def setUp(self): @@ -145,9 +149,7 @@ def test_read_dta4(self): tm.assert_frame_equal(parsed_13, expected) def test_read_write_dta5(self): - if not is_little_endian(): - raise nose.SkipTest("known failure of test_write_dta5 on " - "non-little endian") + skip_if_not_little_endian() original = DataFrame([(np.nan, np.nan, np.nan, np.nan, np.nan)], columns=['float_miss', 'double_miss', 'byte_miss', @@ -161,9 +163,7 @@ def test_read_write_dta5(self): original) def test_write_dta6(self): - if not is_little_endian(): - raise nose.SkipTest("known failure of test_write_dta6 on " - "non-little endian") + skip_if_not_little_endian() original = self.read_csv(self.csv3) original.index.name = 'index' @@ -193,9 +193,7 @@ def test_read_dta9(self): tm.assert_frame_equal(parsed, expected) def test_read_write_dta10(self): - if not is_little_endian(): - raise nose.SkipTest("known failure of test_write_dta10 on " - "non-little endian") + skip_if_not_little_endian() original = DataFrame(data=[["string", "object", 1, 1.1, np.datetime64('2003-12-25')]], @@ -232,6 +230,8 @@ def test_encoding(self): self.assert_(isinstance(result, unicode)) def test_read_write_dta11(self): + skip_if_not_little_endian() + original = DataFrame([(1, 2, 3, 4)], columns=['good', compat.u('b\u00E4d'), '8number', 'astringwithmorethan32characters______']) formatted = DataFrame([(1, 2, 3, 4)], @@ -248,6 +248,8 @@ def test_read_write_dta11(self): tm.assert_frame_equal(written_and_read_again.set_index('index'), formatted) def test_read_write_dta12(self): + skip_if_not_little_endian() + original = DataFrame([(1, 2, 3, 4)], columns=['astringwithmorethan32characters_1', 'astringwithmorethan32characters_2', '+', '-']) formatted = DataFrame([(1, 2, 3, 4)], From 9ed4f7dbdd83b34723de4dd735e5f45277bc3bd7 Mon Sep 17 00:00:00 2001 From: jreback Date: Fri, 27 Dec 2013 14:16:50 -0500 Subject: [PATCH 2/2] BUG: big endian timedelta fix (GH5779) --- pandas/core/common.py | 21 +++++++++++++++------ pandas/core/internals.py | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index 7b652c36ae47d..08061b1d14863 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -40,14 +40,17 @@ class AmbiguousIndexError(PandasError, KeyError): _POSSIBLY_CAST_DTYPES = set([np.dtype(t) - for t in ['M8[ns]', 'm8[ns]', 'O', 'int8', + for t in ['M8[ns]', '>M8[ns]', 'm8[ns]', 'M8[ns]', + 'm8[ns]', 'm8[ns]']]) # define abstract base classes to enable isinstance type checking on our @@ -1572,11 +1575,17 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False): # force the dtype if needed if is_datetime64 and dtype != _NS_DTYPE: - raise TypeError( - "cannot convert datetimelike to dtype [%s]" % dtype) + if dtype.name == 'datetime64[ns]': + dtype = _NS_DTYPE + else: + raise TypeError( + "cannot convert datetimelike to dtype [%s]" % dtype) elif is_timedelta64 and dtype != _TD_DTYPE: - raise TypeError( - "cannot convert timedeltalike to dtype [%s]" % dtype) + if dtype.name == 'timedelta64[ns]': + dtype = _TD_DTYPE + else: + raise TypeError( + "cannot convert timedeltalike to dtype [%s]" % dtype) if np.isscalar(value): if value == tslib.iNaT or isnull(value): diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 6ec08fe501bcd..4e657ca343c12 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1245,8 +1245,10 @@ def _try_operate(self, values): def _try_coerce_result(self, result): """ reverse of try_coerce_args / try_operate """ if isinstance(result, np.ndarray): + mask = isnull(result) if result.dtype.kind in ['i', 'f', 'O']: result = result.astype('m8[ns]') + result[mask] = tslib.iNaT elif isinstance(result, np.integer): result = np.timedelta64(result) return result