Skip to content

Conversation

johannes-mueller
Copy link
Contributor

@johannes-mueller johannes-mueller commented Mar 30, 2023

@property
def dtype(self) -> np.dtype: ...
@property
def dtypes(self) -> pd.Series[Any]: ...
Copy link
Member

Choose a reason for hiding this comment

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

Could probably be tightened to pd.Series[numpy.dtype | pd.api.extensions.ExtensionDtype] but that probably causes trouble (I don't think those classes are part of S1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With pd.Series[numpy.dtype | pd.api.extensions.ExtensionDtype] mypy says

pandas-stubs/core/indexes/multi.pyi:73: error: Invalid type argument value for "Series"  [type-var]
tests/test_indexes.py:862: error: Invalid type argument value for "Series"  [type-var]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, the dtype of the returned Series is object, since it is a Series of dtypes. You could try adding Dtype to S1 in _typing.pyi but that might break other things. If it doesn't break anything, then you could return Series[Dtype]

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

You could try modifying S1 to include Dtype, but if that doesn't work, then just have dtypes return pd.Series.

@property
def dtype(self) -> np.dtype: ...
@property
def dtypes(self) -> pd.Series[Any]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, the dtype of the returned Series is object, since it is a Series of dtypes. You could try adding Dtype to S1 in _typing.pyi but that might break other things. If it doesn't break anything, then you could return Series[Dtype]

@johannes-mueller
Copy link
Contributor Author

You could try modifying S1 to include Dtype, but if that doesn't work, then just have dtypes return pd.Series.

It seems to work in the sense that poe test_all passes in my setup.

@johannes-mueller johannes-mueller requested a review from Dr-Irv March 31, 2023 07:30
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

@Dr-Irv Dr-Irv merged commit 0e1e4c2 into pandas-dev:main Mar 31, 2023
twoertwein pushed a commit to twoertwein/pandas-stubs that referenced this pull request Apr 1, 2023
* Fix MultiIndex.dtypes (pandas-dev#597)

* Tighten the MultiIndex.dtypes return value to Dtype
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.

MultiIndex stub lacks dtypes property

3 participants