Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DEP: issue deprecation warning when creating ragged array (NEP 34) #14794

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 10 commits into from
Dec 3, 2019

Conversation

mattip
Copy link
Member

@mattip mattip commented Oct 28, 2019

A demo of the direction of Implement NEP 34 (deprecating automatic object detection of ragged arrays). It seems to work except for including record arrays

>>> descr = [('v', int, 3), ('x', [('y', float)])]
>>> x = np.array([
...             [([1, 2, 3], (1.0,)),  ([1, 2, 3], (2.0,))],
...             [([1, 2, 3], (3.0,)),  ([1, 2, 3], (4.0,))]], dtype=descr)

I needed to filter the DeprecationWarning in `assert_equal(x, y) since they could be ragged lists.

@@ -1073,34 +1073,60 @@ def test_array_too_big(self):
assert_raises(ValueError, np.ndarray, buffer=buf, strides=(0,),
shape=(max_bytes//itemsize + 1,), dtype=dtype)

def test_jagged_ndim_object(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the real NEP 34 tests (from here down in this file): they test that the behaviour has not changed when using the dtype=object kwarg, and that the warning does not seem to have false-positives when no dtype is used.

@mattip mattip changed the title WIP, DEP: issue deprecation warning when creating ragged array (NEP 34) DEP: issue deprecation warning when creating ragged array (NEP 34) Oct 31, 2019
Copy link
Member Author

@mattip mattip left a comment

Choose a reason for hiding this comment

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

need to fix the release note link once NEP 34 is published

Edit: done

@mattip
Copy link
Member Author

mattip commented Nov 5, 2019

The ppc64le build failure is not related to this PR.

@mattip
Copy link
Member Author

mattip commented Nov 7, 2019

I think it would be good to get this into 1.18 so it can be deprecated in 1.20

@mattip
Copy link
Member Author

mattip commented Nov 23, 2019

The NEP was accepted, this is ready for final review

@mattip mattip added this to the 1.18.0 release milestone Nov 23, 2019
@mattip mattip requested a review from eric-wieser November 25, 2019 18:00
@mattip mattip removed this from the 1.18.0 release milestone Nov 27, 2019
@seberg seberg self-requested a review November 27, 2019 19:32
@@ -17,6 +17,7 @@
{% if definitions[category]['showcontent'] %}
{% for text, values in sections[section][category].items() %}
{{ text }}

Copy link
Member

Choose a reason for hiding this comment

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

Stray or deliberate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Deliberate. The changenote has a link as the last line, which confuses sphinx when assembling the notes into the final text unless it is followed by a blank line

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Looks good to me, probably worth a quick lookover by @seberg

# None of these should raise, even though they are missing dtype=object
a = np.array([[[Decimal(1)]]])
a = np.array([1, Decimal(1)])
a = np.array([[1], [Decimal(1)]])
Copy link
Member

@seberg seberg Dec 2, 2019

Choose a reason for hiding this comment

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

In principle could be nice to add that similar cases (also None) such as [None, [None, None]] do correctly warn. (although maybe I missed a test that checks this already)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean specifically ragged lists of objects? In the tests above this ragged arrays of integers are checked.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Cool! Looks good to me. Did not really expect it would be quite this simple :). From my side, can be merged right away.

/* NumPy 1.18, 2019-11-01 */
if (DEPRECATE("Creating an ndarray with automatic object "
"dtype is deprecated, use dtype=object if you intended "
"it, otherwise specify an exact dtype") < 0)
Copy link
Member

Choose a reason for hiding this comment

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

could style nit, that the indentation should be deeper, but please ignore if you want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will try to sneak it into another PR

@rgommers rgommers added this to the 1.18.0 release milestone Dec 3, 2019
@rgommers rgommers merged commit 3a9a63f into numpy:master Dec 3, 2019
@rgommers
Copy link
Member

rgommers commented Dec 3, 2019

Looks good to me, merged. @mattip there's two optional comments from @seberg that could be nice to address. Not essential that those go into 1.18.x it looks like.

charris added a commit to charris/numpy that referenced this pull request Dec 4, 2019
This reverts commit 3a9a63f, reversing
changes made to 7999f7c.

A lot of problems have been exposed by this change, so best to leave it
out of the 1.18.x series and work on it in master.
charris added a commit that referenced this pull request Dec 4, 2019
REV: Revert "Merge pull request #14794 from mattip/nep-0034-impl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants