[SciPy-dev] Don't understand these results

David Goldsmith d_l_goldsmith at yahoo.com
Mon Aug 17 02:34:20 EDT 2009


--- On Sun, 8/16/09, Pierre GM <pgmdevlist at gmail.com> wrote:

> 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 ?

I "take the 5th." ;-)

> 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 would explain it.

> 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  
> account.
>  >>> 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.

NP, understood 100%

> Try to  
> fill a ticket on the numpy trac.

Will do, presently.

> Many thanks for reporting.

You're welcome.  (Never sure anymore whether odd behavior is a bug or a feature...)

DG

> 
> 
> 
> 
> 
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
> 


      



More information about the SciPy-Dev mailing list