[SciPy-dev] Don't understand these results

Pierre GM pgmdevlist@gmail....
Mon Aug 17 01:19:36 CDT 2009

On Aug 17, 2009, at 1:35 AM, David Goldsmith wrote:

>>>> c = np.array(['aAaAaA', '  aA  ', 'abBABba']).view(np.chararray); c
> chararray(['aAaAaA', '  aA', 'abBABba'],
>      dtype='|S7')
>>>> c.count('aA', end=3)
> array([3, 1, 0])
> ???

Have you checked the code ?

The input of the method ('aA',start,end)  are checked for consistency.  
However, a problem is that as soon any value is 0 or None or False,  
the following values are not checked and just discarded (that's line  
171 in defchararray).
When you call the `count` method, `start` defaults to None, meaning  
that the `end` parameter is never taken into account.

That's clearly a bug, actually 2 bugs:
* `start` should default to 0 in that case (you need it in the `count`  
method of strings)
* when one of the parameter is not None, it should be taken into  
 >>> if not chk or (chk.dtype is object_ and chk.item() is None):
should become
 >>> if (chk is None) of (chk.dtype is object_ and chk.item() is None):

I don't have time to spend on fixing that right now, sorry. Try to  
fill a ticket on the numpy trac.
Many thanks for reporting.

More information about the Scipy-dev mailing list