Skip to content

BUG: add a special case for StringDType in np.isdtype - #32030

Merged
ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:isdtype-stringdtype
Jul 18, 2026
Merged

BUG: add a special case for StringDType in np.isdtype#32030
ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:isdtype-stringdtype

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

PR summary

Fixes #27545.

I don't see a cleaner way to fix this without just adding a special case in the error path. This function is only for built-in NumPy DTypes so it would be a bigger change to just make it return True if it's handed a dtype or dtypemeta instance, which is probably a more principled fix.

AI Disclosure

No AI use on this one.

@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Jul 17, 2026
@seberg

seberg commented Jul 17, 2026

Copy link
Copy Markdown
Member

Note that this would be superseded by gh-31755, but I need to file it (and make a decision if we expose .register() or not, but I am OK with just not doing it for now).

But as always, that doens't mean we can't just do this now :).

@seberg seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems simple enough, so happy if you put it in, just a small merge conflict for the other PR.

# dtype parameters are ignored, like datetime64 units
assert np.isdtype(np.dtypes.StringDType(na_object=None), dt)
assert np.isdtype(dt, np.dtypes.StringDType(na_object=np.nan,
coerce=False))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah one note: I think I would want to deprecate this. It doesn't actually make much sense, because to ask it for a dtype instance as second argument, IMO.
(Even if it is convenient.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, I can add that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you like to do it for all inputs, but can also do it in the other PR, I dunno how nice it is without the changes around.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah in that case why don't you add the deprecation in the other PR. You have more context here than I do.

@ngoldbaum
ngoldbaum merged commit 7e1f944 into numpy:main Jul 18, 2026
92 checks passed
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 27, 2026
charris added a commit that referenced this pull request Jul 27, 2026
BUG: add a special case for StringDType in np.isdtype (#32030)
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Aug 4, 2026
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.

ENH: numpy.isdtype with custom dtypes

3 participants