8000 BUG: Fix object scalar return type of 0-d array indices by seberg · Pull Request #4109 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix object scalar return type of 0-d array indices #4109

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 22, 2013

Conversation

seberg
Copy link
Member
@seberg seberg commented Dec 6, 2013

PyArray_Result was called when it should not have been. This caused
object arrays of 0-d arrays have the inner array converted to a
scalar:

np.array([np.array(0), None])[0] -> np._float(0)

The same case happened to recarray field access. This fixes it.

(This was an SO question, maybe it will be an issue here, too... It is a regression in 1.8.x). There are some code blocks there I am sure are not used, but I don't want to touch the old mapping.c more then absolutely necessary... My current plan is, that when this is merged I create a blocker issue for 1.9.x. My indexing branch has it fixed anyway, I know that is not the right procedure, so if someone disagrees...

return PyArray_Return((PyArrayObject *)ret);
}
return ret;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the only thing that block does is probably should be to more or less correctly support arr['0', '0'] or broken types, and my new stuff doesn't have that yet... (something like this was probably historically always there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation of '}' ?

hpaulj pushed a commit to hpaulj/numpy that referenced this pull request Dec 6, 2013
return array_subscript_fancy(self, op, fancy);
}
PyObject *ret;
8000 ret = array_subscript_fancy(self, op, fancy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line might look better if it were swapped with the following blank line.

@charris
Copy link
Member
charris commented Dec 19, 2013

Looks good modulo style nitpicks. I'm relying on the tests to check that the code does what is claimed ;)

PyArray_Result was called when it should not have been. This caused
object arrays of 0-d arrays have the inner array converted to a
scalar:

`np.array([np.array(0), None])[0] -> np._float(0)`

The same case happened to recarray field access when indexing
more than one field. This fixes it.
@seberg
Copy link
Member Author
seberg commented Dec 19, 2013

Good, luckily, all cases which should not result in an array go normally through their own special case, so I don't think I can break anything ;). Fixed the style nitpicks, but want confirmation that fixing a[['a']] to be identical to a['a'] is good.

@charris
Copy link
Member
charris commented Dec 19, 2013

Fixed the style nitpicks, but want confirmation that fixing a[['a']] to be identical to a['a'] is good.

These distinctions make my head hurt ;) I'm not clear on what the intent of a[['a']] was, perhaps this should be run past the list to see if there was a reason for the current behavior.

@charris
Copy link
Member
charris commented Dec 22, 2013

@seberg There doesn't seem to be much response on the list. Is this fixed in master? Fixing it in 1.8 doesn't bother me and a[['a']] returning a scalar is definitely weird. So in it goes. However, I don't think a 1.8.1 is due unless a fix for #4118 goes in.

charris added a commit that referenced this pull request Dec 22, 2013
BUG: Fix object scalar return type of 0-d array indices
@charris charris merged commit 09f139a into numpy:maintenance/1.8.x Dec 22, 2013
@seberg seberg deleted the scalar-object-indexing branch December 22, 2013 20:25
@seberg
Copy link
Member Author
seberg commented Dec 22, 2013

I admit, master currently doesn't, I opened a 1.9. blocker about it though. My indexing stuff does mostly (except for the one corner case at this time).

8000
@juliantaylor
Copy link
Contributor

this fix breaks pandas 0.13, you get lots of test failures of these types:

ERROR: test_qcut_specify_quantiles (pandas.tools.tests.test_tile.TestCut)
  File "hashtable.pyx", line 776, in pandas.hashtable.PyObjectHashTable.unique (pandas/hashtable.c:12071)
TypeError: unhashable type: 'numpy.ndarray'

FAIL: test_series_describe_multikey (pandas.tests.test_groupby.TestGroupBy)
    assert a == b, "%s: %r != %r" % (msg.format(a,b), a, b)
AssertionError: attr is not equal [dtype]: dtype('O') != dtype('float64')

the fix is also in the 1.8.x branch so pandas is also broken there whih must be accounted for should a 1.8.1 be made

@juliantaylor
Copy link
Contributor

as pointed out in the pandas issue the maintenance branch is broken by this:
master doesn't contain this commit at all so its fine.

In [5]: a=np.array([1,2,3])
   ...: a[1.1]
Out[5]: array(2)

surprising we don't have a test for this.

@seberg do you have time too look at this or should we just revert it for now?

@seberg
Copy link
Member Author
seberg commented Jan 22, 2014

Oh, I think I will fix it soon. Just need to look through the subtleties and best check what 1.7 did. A mostly fix is simple in any case and quite right may be impossible, but it should match 1.7. if possible...

@seberg
Copy link
Mem 794A ber Author
seberg commented Jan 23, 2014

@juliantaylor, see gh-4223.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0