Closed cmp0xff closed 2 months ago
Hi @Dr-Irv thank you for the comment. In https://github.com/pandas-dev/pandas-stubs/issues/983#issuecomment-2301853575 you mentioned:
The declaration of
match()
incore/strings.pyi
is incorrect.
I partially fixed it.
Series.str.match
.str.match
is called.
Series
, the return type is Series[bool]
, as is fixedIndex
, the return type is npt.NDArray[np.bool_]
, as in #983 How can I capture this expectation?
But to fix it, the
StringMethods
class will need an additional argument to pass in the expected result ofmatch()
, similar to what is done withstr.split()
.
I do not get this suggestion. Could you elaborate?
PR with tests welcome
How can I capture this expectation?
But to fix it, the
StringMethods
class will need an additional argument to pass in the expected result ofmatch()
, similar to what is done withstr.split()
.I do not get this suggestion. Could you elaborate?
In core/strings.pyi
, we have this:
# The _TS type is what is used for the result of str.split with expand=True
_TS = TypeVar("_TS", DataFrame, MultiIndex)
class StringMethods(NoNewAttributesMixin, Generic[T, _TS]):
You need to create an additional TypeVar
, let's call it _MR
(for match result). Then the Generic
part of StringMethods
adds _MR
to the parameters of Generic
.
Then the match()
method would return _MR
.
Then you change the references to StringMethods
in core/series.pyi
and core/indexes/base.pyi
to pass in the correct type of result you want match
to return as the 3rd argument.
See the pattern used with split()
- that's how we control the return type of that particular method.
I'll let you address that change before firing off the CI.
Hi @Dr-Irv , thanks for the explanations. I have made the changes.
assert_type()
to assert the type of any return value