From 0dc6428bcf96daf2bd66994f2f1b3a2be941e4e0 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Tue, 2 Dec 2014 22:23:37 -0500 Subject: [PATCH] TST: tests for lib.max_len_string_array COMPAT: unicode for same --- pandas/lib.pyx | 6 +++--- pandas/tests/test_lib.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pandas/lib.pyx b/pandas/lib.pyx index 82408cd460fcd..2a5b93d111acc 100644 --- a/pandas/lib.pyx +++ b/pandas/lib.pyx @@ -898,17 +898,17 @@ def clean_index_list(list obj): @cython.boundscheck(False) @cython.wraparound(False) -def max_len_string_array(ndarray[object, ndim=1] arr): +def max_len_string_array(ndarray arr): """ return the maximum size of elements in a 1-dim string array """ cdef: int i, m, l - length = arr.shape[0] + int length = arr.shape[0] object v m = 0 for i from 0 <= i < length: v = arr[i] - if PyString_Check(v) or PyBytes_Check(v): + if PyString_Check(v) or PyBytes_Check(v) or PyUnicode_Check(v): l = len(v) if l > m: diff --git a/pandas/tests/test_lib.py b/pandas/tests/test_lib.py index 2873cd81d4744..1276a7fc96a46 100644 --- a/pandas/tests/test_lib.py +++ b/pandas/tests/test_lib.py @@ -3,10 +3,21 @@ import numpy as np import pandas as pd -from pandas.lib import isscalar, item_from_zerodim +from pandas.lib import isscalar, item_from_zerodim, max_len_string_array import pandas.util.testing as tm from pandas.compat import u +class TestMisc(tm.TestCase): + + def test_max_len_string_array(self): + + arr = np.array(['foo','b',np.nan],dtype='object') + self.assertTrue(max_len_string_array(arr),3) + + # unicode + arr = arr.astype('U') + self.assertTrue(max_len_string_array(arr),3) + class TestIsscalar(tm.TestCase): def test_isscalar_builtin_scalars(self): self.assertTrue(isscalar(None))