From ef085467f86d787c8b7ae0f0bd5c9e3a43f34360 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 20 Jul 2015 23:06:17 -0700 Subject: [PATCH] BUG: Fixed typo-related bug to resolve #9266 Fixed typo in _convert_to_ndarrays Added tests for typo fix --- doc/source/whatsnew/v0.17.0.txt | 2 ++ pandas/io/parsers.py | 2 +- pandas/io/tests/test_parsers.py | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index 206c5e2e22711..8b8ea0c38f613 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -390,3 +390,5 @@ Bug Fixes - Reading "famafrench" data via ``DataReader`` results in HTTP 404 error because of the website url is changed (:issue:`10591`). - Bug in `read_msgpack` where DataFrame to decode has duplicate column names (:issue:`9618`) + +- Bug in `_convert_to_ndarrays` which caused an `AttributeError` to be raised at times (:issue:`9266`) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 62d51fc510f97..ad9823da5851b 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -995,7 +995,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False, try: values = lib.map_infer(values, conv_f) except ValueError: - mask = lib.ismember(values, na_values).view(np.uin8) + mask = lib.ismember(values, na_values).view(np.uint8) values = lib.map_infer_mask(values, conv_f, mask) coerce_type = False diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 0f0486e8ea596..baee082f16abd 100755 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -2654,6 +2654,27 @@ def test_fwf_regression(self): res = df.loc[:,c] self.assertTrue(len(res)) + def test_fwf_for_uint8(self): + data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127 +1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" + df = read_fwf(StringIO(data), + colspecs=[(0,17),(25,26),(33,37),(49,51),(58,62),(63,1000)], + names=['time','pri','pgn','dst','src','data'], + converters={ + 'pgn':lambda x: int(x,16), + 'src':lambda x: int(x,16), + 'dst':lambda x: int(x,16), + 'data':lambda x: len(x.split(' '))}) + + expected = DataFrame([[1421302965.213420,3,61184,23,40,8], + [1421302964.226776,6,61442,None, 71,8]], + columns = ["time", "pri", "pgn", "dst", "src","data"]) + + # Hacky fix for dst column dtype + expected["dst"] = expected["dst"].astype(object) + + tm.assert_frame_equal(df, expected) + def test_fwf_compression(self): try: import gzip