Skip to content

TST/COMPAT: tests and compat for unicode for lib.max_len_string_array #8978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion pandas/tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down