Skip to content

Commit 384eb45

Browse files
captainsafiajreback
authored andcommitted
BUG: Fixed typo-related bug to resolve #9266
Fixed typo in _convert_to_ndarrays Added tests for typo fix
1 parent d065374 commit 384eb45

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ Bug Fixes
376376
- Bug in `Series.from_csv` with ``header`` kwarg not setting the ``Series.name`` or the ``Series.index.name`` (:issue:`10483`)
377377
- Bug in `groupby.var` which caused variance to be inaccurate for small float values (:issue:`10448`)
378378
- Bug in ``Series.plot(kind='hist')`` Y Label not informative (:issue:`10485`)
379+
- Bug in ``read_csv`` when using a converter which generates a ``uint8`` type (:issue:`9266`)
379380

380381

381382

pandas/io/parsers.py

+1-1
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

+20-1
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,25 @@ 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+
expected["dst"] = expected["dst"].astype(object)
2673+
2674+
tm.assert_frame_equal(df, expected)
2675+
26572676
def test_fwf_compression(self):
26582677
try:
26592678
import gzip
@@ -3594,7 +3613,7 @@ def test_empty_with_dup_column_pass_dtype_by_indexes(self):
35943613

35953614
data = 'one,one'
35963615
result = self.read_csv(StringIO(data), mangle_dupe_cols=False, dtype={0: 'u1', 1: 'f'})
3597-
expected = pd.concat([Series([], name='one', dtype='u1'),
3616+
expected = pd.concat([Series([], name='one', dtype='u1'),
35983617
Series([], name='one', dtype='f')], axis=1)
35993618
tm.assert_frame_equal(result, expected)
36003619

0 commit comments

Comments
 (0)