Skip to content

Commit ef08546

Browse files
committed
BUG: Fixed typo-related bug to resolve pandas-dev#9266
Fixed typo in _convert_to_ndarrays Added tests for typo fix
1 parent a3cca39 commit ef08546

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

doc/source/whatsnew/v0.17.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,5 @@ Bug Fixes
390390
- Reading "famafrench" data via ``DataReader`` results in HTTP 404 error because of the website url is changed (:issue:`10591`).
391391

392392
- Bug in `read_msgpack` where DataFrame to decode has duplicate column names (:issue:`9618`)
393+
394+
- Bug in `_convert_to_ndarrays` which caused an `AttributeError` to be raised at times (:issue:`9266`)

pandas/io/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
995995
try:
996996
values = lib.map_infer(values, conv_f)
997997
except ValueError:
998-
mask = lib.ismember(values, na_values).view(np.uin8)
998+
mask = lib.ismember(values, na_values).view(np.uint8)
999999
values = lib.map_infer_mask(values, conv_f, mask)
10001000
coerce_type = False
10011001

pandas/io/tests/test_parsers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,27 @@ def test_fwf_regression(self):
26542654
res = df.loc[:,c]
26552655
self.assertTrue(len(res))
26562656

2657+
def test_fwf_for_uint8(self):
2658+
data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127
2659+
1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71"""
2660+
df = read_fwf(StringIO(data),
2661+
colspecs=[(0,17),(25,26),(33,37),(49,51),(58,62),(63,1000)],
2662+
names=['time','pri','pgn','dst','src','data'],
2663+
converters={
2664+
'pgn':lambda x: int(x,16),
2665+
'src':lambda x: int(x,16),
2666+
'dst':lambda x: int(x,16),
2667+
'data':lambda x: len(x.split(' '))})
2668+
2669+
expected = DataFrame([[1421302965.213420,3,61184,23,40,8],
2670+
[1421302964.226776,6,61442,None, 71,8]],
2671+
columns = ["time", "pri", "pgn", "dst", "src","data"])
2672+
2673+
# Hacky fix for dst column dtype
2674+
expected["dst"] = expected["dst"].astype(object)
2675+
2676+
tm.assert_frame_equal(df, expected)
2677+
26572678
def test_fwf_compression(self):
26582679
try:
26592680
import gzip

0 commit comments

Comments
 (0)