Skip to content

Conversation

@seberg
Copy link
Member

@seberg seberg commented Oct 15, 2025

Small fix for resize with objects, which was always broken.

@mhvk one little thing is that we of course don't need to do this in all of the internal places in theory.

Closes gh-29887.

Copy link
Contributor

@mhvk mhvk 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, just one missing assert.

test_obj = object()
expected = sys.getrefcount(test_obj)
a = np.array([test_obj, test_obj, test_obj], dtype=dtype)
a.size == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing assert here!

@mhvk
Copy link
Contributor

mhvk commented Oct 15, 2025

@mhvk one little thing is that we of course don't need to do this in all of the internal places in theory.

For object arrays, I think it pays to just be correct -- and everything is slow anyway,

assert a.size == 2
del a
# if all is well, then we reclaimed all references
assert sys.getrefcount(test_obj) == expected
Copy link
Member

Choose a reason for hiding this comment

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

not available on pypy

Copy link
Contributor

@mhvk mhvk 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!

@ngoldbaum ngoldbaum merged commit e6478c5 into numpy:main Oct 28, 2025
79 of 80 checks passed
@ngoldbaum
Copy link
Member

Thanks @seberg thanks for the nudge.

@seberg seberg deleted the resize-cleanup branch October 28, 2025 18:27
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Oct 28, 2025
charris pushed a commit to charris/numpy that referenced this pull request Oct 28, 2025
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Oct 28, 2025
charris added a commit that referenced this pull request Oct 29, 2025
BUG: Fix resize when it contains references (#29970)
cakedev0 pushed a commit to cakedev0/numpy that referenced this pull request Dec 5, 2025
IndifferentArea pushed a commit to IndifferentArea/numpy that referenced this pull request Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: shrinking an object array with .resize does not decref the shrunk items

4 participants