-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: Deprecate ravel #56053
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
DEPR: Deprecate ravel #56053
Changes from 7 commits
b2f2774
41f31aa
dd9cfe6
054ca87
5a15389
28fb76c
636e3c4
d48e5ca
146e1aa
5be6f6c
571bc1a
d54a80c
cf79da9
4afe81c
bd292ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -858,9 +858,14 @@ def ravel(self, order: str = "C") -> ArrayLike: | |||||
Examples | ||||||
-------- | ||||||
>>> s = pd.Series([1, 2, 3]) | ||||||
>>> s.ravel() | ||||||
>>> s.ravel() # doctest: +SKIP | ||||||
array([1, 2, 3]) | ||||||
""" | ||||||
warnings.warn( | ||||||
"Series.ravel is deprecated. Use numpy.ravel directly.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe we should also point to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or just "dont do it bc it isnt necessary"? (also should we deprecate Index.ravel?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's not necessarily correct. If you rely on the current return value, i.e. if your code requires that the object is a 1D numpy array, and you currently use |
||||||
FutureWarning, | ||||||
stacklevel=find_stack_level(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For a simple case like this where the warning is directly raised in the top-level method, I prefer setting it explicitly, which avoids potential hickups with the function (I think we had perf issues in certain cases, and this also avoids getting a wrong stacklevel in case we forget a use case of ravel in our own code base) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||||||
) | ||||||
arr = self._values.ravel(order=order) | ||||||
if isinstance(arr, np.ndarray) and using_copy_on_write(): | ||||||
arr.flags.writeable = False | ||||||
|
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.
Should we do that inside
maybe_downcast_to_dtype
instead? That function is also used in some other places (I don't know if it is guaranteed to be called with a non-Series in those other places, but our test coverage might also be lacking on that aspect)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.
sure