Skip to content

MNT: remove some obsolete string to bool workarounds#31859

Open
ikrommyd wants to merge 4 commits into
numpy:mainfrom
ikrommyd:cleanup-count-nonzero
Open

MNT: remove some obsolete string to bool workarounds#31859
ikrommyd wants to merge 4 commits into
numpy:mainfrom
ikrommyd:cleanup-count-nonzero

Conversation

@ikrommyd

@ikrommyd ikrommyd commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

PR summary

Refactors an array conversion to boolean dtype in count_nonzero to a a one-liner.
Just a small TODO I found while scrolling around the codebase.
This should work now given gh-9847 and the issue that superseded it gh-9875 are resolved and the extra np.character branch should be unnecessary.

Edit: I found a test that can be enabled too I think in test_array_coercion.py for the same reason just by searching for these issue numbers in the codebase

First time committer introduction

N/A

AI Disclosure

No AI

@ikrommyd ikrommyd changed the title MNT: a.astype(np.bool) should work not for count_nonzero MNT: minor refactor of array conversion to boolean dtype in count_nonzero to a one-liner Jul 4, 2026
@ikrommyd ikrommyd changed the title MNT: minor refactor of array conversion to boolean dtype in count_nonzero to a one-liner MNT: remove unnecessary np.character branch for array conversion to boolean dtype in count_nonzero Jul 4, 2026
@ikrommyd ikrommyd changed the title MNT: remove unnecessary np.character branch for array conversion to boolean dtype in count_nonzero MNT: remove some obsolete string to bool workarounds Jul 4, 2026
@ikrommyd ikrommyd force-pushed the cleanup-count-nonzero branch from cca5338 to 809e62b Compare July 4, 2026 06:14
Signed-off-by: Iason Krommydas <[email protected]>
Comment thread numpy/_core/numeric.py Outdated
else:
a_bool = a.astype(np.bool, copy=False)

a_bool = a.astype(np.bool, copy=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

asanyarray has a dtype and copy argument. Can this cast be combined with the previous line?

@ikrommyd ikrommyd Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah with copy=None which is the default in asanyarray it should be equivalent. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants