-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
block mutation of read-only array in series #14359
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
Changes from all 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 |
---|---|---|
|
@@ -975,7 +975,9 @@ def astype_intsafe(ndarray[object] arr, new_dtype): | |
if is_datelike and checknull(v): | ||
result[i] = NPY_NAT | ||
else: | ||
util.set_value_at(result, i, v) | ||
# we can use the unsafe version because we know `result` is mutable | ||
# since it was created from `np.empty` | ||
util.set_value_at_unsafe(result, i, v) | ||
|
||
return result | ||
|
||
|
@@ -986,7 +988,9 @@ cpdef ndarray[object] astype_unicode(ndarray arr): | |
ndarray[object] result = np.empty(n, dtype=object) | ||
|
||
for i in range(n): | ||
util.set_value_at(result, i, unicode(arr[i])) | ||
# we can use the unsafe version because we know `result` is mutable | ||
# since it was created from `np.empty` | ||
util.set_value_at_unsafe(result, i, unicode(arr[i])) | ||
|
||
return result | ||
|
||
|
@@ -997,7 +1001,9 @@ cpdef ndarray[object] astype_str(ndarray arr): | |
ndarray[object] result = np.empty(n, dtype=object) | ||
|
||
for i in range(n): | ||
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. this should simply be checked once for the array (and don't call the unsafe function) 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. We don't need an explicit check because we created this array with np.empty so it is mutable. The 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. right, I read them backwards.....ok 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. so perf basically the same then for non-readonly arrays? 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. On this line, it is always readonly. The only places where we call this in a loop are with known writeable arrays created by empty. In those cases we are going through the exact same code path as before, the function was just renamed to |
||
util.set_value_at(result, i, str(arr[i])) | ||
# we can use the unsafe version because we know `result` is mutable | ||
# since it was created from `np.empty` | ||
util.set_value_at_unsafe(result, i, str(arr[i])) | ||
|
||
return result | ||
|
||
|
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.
same here (and anywhere there is a range)