-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Sparse array cumsum leads to infinite recursion 62669 #62703
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1571,6 +1571,9 @@ def cumsum(self, axis: AxisInt = 0, *args, **kwargs) -> SparseArray: | |||||||||||
| raise ValueError(f"axis(={axis}) out of bounds") | ||||||||||||
|
|
||||||||||||
| if not self._null_fill_value: | ||||||||||||
| if isinstance(self, SparseArray) and self.fill_value == 0: | ||||||||||||
| # special case where we can avoid max recursion depth | ||||||||||||
| return SparseArray(self.to_dense().cumsum()) | ||||||||||||
|
||||||||||||
| if not self._null_fill_value: | |
| if isinstance(self, SparseArray) and self.fill_value == 0: | |
| # special case where we can avoid max recursion depth | |
| return SparseArray(self.to_dense().cumsum()) | |
| if not self._null_fill_value and self.fill_value != 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.
I see now this was wrong, but the previous implementation also did not handle the case
arr = pd.arrays.SparseArray([1.0, 0.0, np.nan, 3.0], fill_value=0.0)correctly as it would have given the result [1.0, 1.0, nan, nan] whereas I believe docstring indicates the result should be [1.0, 1.0, nan, 4.0]. We can accomplish this by:
if not self._null_fill_value:
return SparseArray(self.to_dense(), fill_value=np.nan).cumsum()Note this changes the fill_value to NaN, but that adheres to the docstring. Anytime this method has been successful in previous versions, it was always returning an NA fill value regardless of the input fill value. So I think we should stick to that logic at least for now.
Uh oh!
There was an error while loading. Please reload this page.