Skip to content

Commit b89fc70

Browse files
committed
Merge pull request #8978 from jreback/unicode
TST/COMPAT: tests and compat for unicode for lib.max_len_string_array
2 parents 6565591 + 0dc6428 commit b89fc70

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pandas/lib.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,17 +898,17 @@ def clean_index_list(list obj):
898898

899899
@cython.boundscheck(False)
900900
@cython.wraparound(False)
901-
def max_len_string_array(ndarray[object, ndim=1] arr):
901+
def max_len_string_array(ndarray arr):
902902
""" return the maximum size of elements in a 1-dim string array """
903903
cdef:
904904
int i, m, l
905-
length = arr.shape[0]
905+
int length = arr.shape[0]
906906
object v
907907

908908
m = 0
909909
for i from 0 <= i < length:
910910
v = arr[i]
911-
if PyString_Check(v) or PyBytes_Check(v):
911+
if PyString_Check(v) or PyBytes_Check(v) or PyUnicode_Check(v):
912912
l = len(v)
913913

914914
if l > m:

pandas/tests/test_lib.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
import numpy as np
44

55
import pandas as pd
6-
from pandas.lib import isscalar, item_from_zerodim
6+
from pandas.lib import isscalar, item_from_zerodim, max_len_string_array
77
import pandas.util.testing as tm
88
from pandas.compat import u
99

10+
class TestMisc(tm.TestCase):
11+
12+
def test_max_len_string_array(self):
13+
14+
arr = np.array(['foo','b',np.nan],dtype='object')
15+
self.assertTrue(max_len_string_array(arr),3)
16+
17+
# unicode
18+
arr = arr.astype('U')
19+
self.assertTrue(max_len_string_array(arr),3)
20+
1021
class TestIsscalar(tm.TestCase):
1122
def test_isscalar_builtin_scalars(self):
1223
self.assertTrue(isscalar(None))

0 commit comments

Comments
 (0)