Skip to content

charray.count() "breaks" if kwarg 'end' assigned but 'start' isn't (Trac #1195) #1793

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

Closed
thouis opened this issue Oct 19, 2012 · 3 comments
Closed
Labels
00 - Bug component: numpy._core Priority: high High priority, also add milestones for urgent issues
Milestone

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1195 on 2009-08-17 by trac user dgoldsmith, assigned to unknown.

Example:

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]

Problem (as reported by Pierre GM):

"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
    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):"

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

@mdboom wrote on 2009-10-12

This bug is addressed by the chararray refactoring I did in SVN r7514. It's difficult to create a simple patch for this bug, as part of its solution involved vectorizing the string operation in C.

Is there no way to mark this as "fixed" without attaching a patch?

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

Milestone changed to 1.4.0 by @cournape on 2009-11-25

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

@teoliphant wrote on 2009-12-04

It looks like this is "fixed".

@thouis thouis closed this as completed Oct 19, 2012
certik pushed a commit to certik/numpy that referenced this issue Nov 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug component: numpy._core Priority: high High priority, also add milestones for urgent issues
Projects
None yet
Development

No branches or pull requests

1 participant