-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Conversation
@@ -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): |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
The ppc64le build failure is not related to this PR. |
I think it would be good to get this into 1.18 so it can be deprecated in 1.20 |
The NEP was accepted, this is ready for final review |
@@ -17,6 +17,7 @@ | |||
{% if definitions[category]['showcontent'] %} | |||
{% for text, values in sections[section][category].items() %} | |||
{{ text }} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray or deliberate?
There was a problem hiding this comment.
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
There was a problem hiding this 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)]]) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
REV: Revert "Merge pull request #14794 from mattip/nep-0034-impl"
A demo of the direction ofImplement NEP 34 (deprecating automatic object detection of ragged arrays). It seems to workexcept forincluding record arraysI needed to filter the DeprecationWarning in `assert_equal(x, y) since they could be ragged lists.