-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
TYP: Add type stubs for stringdtype in np.char and np.strings #27470
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
Conversation
Since |
Maybe I'm missing something, but the second argument of And |
Ah after applying my mental autocorrect function, I realized that you're talking about Anyway, I don't think that the issue here has to do with the fact that @overload
def strip(a: S_co, chars: None | S_co = ...) -> np.ndarray[_Shape, np.dtypes.StringDType]: ... The When call So to make a short story long: the |
Argh, so it looks like the mypy tests are failing here and they didn't fail locally for me because this PR branch is based on After #27419, this is no longer an error and I have no idea why:
(Note that this is after fixing a logic error in |
b8ad836
to
16cb6de
Compare
16cb6de
to
4268322
Compare
I think I responded to everything with the latest push. |
I'll finish this off if I can get some help with the test failures and the question I just posted above. |
The test failure seems to be a result of an import issue with So when mypy doesn't know what something is, it just treats is as if its |
OK, only remaining failure I see is unrelated. Thanks so much for your help with this @jorenham! |
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.
Mypy is still reporting some overload-overlap
errors in defchararray.pyi
, but I believe those are false positives (i.e. one of those oh-so-familiar mypy bugs), and Pyright seems to be happy with them.
There are some minor opportunities for improvement left, but as far as I'm concerned, those shouldn't be the deal-breakers for merging.
Apart form the review comment I left, I'm referring here to how most overloads could be "merged" through using a TypeVar
with constraints, but it's probably cleaner to address this in seperate PR now that I think about it 🤔.
Anyway, it's very nice to see that _core/strings.pyi
is completely error free (which unfortunately is a rare signt in the numpy stubs at the moment).
It's also worth noting that pyright appears to agree with mypy on all relevant type-tests (and that's far from trivial), which is a very good sign.
So thanks for your effort and your patience; typing in Python is tricky, but you seem to have a knack for it 👌🏻.
tldr; I'm happy to merge this if you want, so let me me know if you plan on changing anything (e.g. the tags suggest you want to add some release notes?)
Needs rebase, some of the reveal tests have been removed. |
I'll try to get this updated soon, I just finished a short vacation today and hopefully I'll have some time to work on this later this week. |
13fa9ce
to
46844ca
Compare
I think this is good to merge now. |
I agree 👌🏻 |
Thanks @ngoldbaum! |
This is definitely an improvement but there are still some issues.
@jorenham pointed out (unfortunately after I pushed everything) that we can substantially simplify some of these overloads using a
TypeVar
.I also am not able to make expression like
np.split(AR_S, ' ')
type check properly, since from the type-checker's perspective' '
is convertible to a unicode array, but in reality in the way we set up the promoters for StringDType, this does return a StringDType array. I had to cheat for functions like that where normally people pass scalars but it's typed to be able to accept an array by passing in anAR_S
in the reveal tests where the unicode tests pass in a scalar.There were also a couple of functions that were missing tests and I've added them.