Skip to content

Series.dtype property return the wrong type #216

Closed
@jasonboh

Description

@jasonboh

Describe the bug
The Series.dtype property is defined as "Union[ExtensionDtype, str, dtype[generic], Type[object]]". However, I believe this is incorrect. I noticed the problem when using the dtype.kind property. There is no way that I can think of that series.dtype.kind should fail. And there's no way I can think of that series.dtype returns a string. When you are creating a Series, you can indeed input a string that resolves into a dtype (as shown in my code snippet below), but the Series.dtype property always returns a dtype, not a string. Even pandas extension arrays, , for example those with the nullable ints or strings, have a "kind" property.

To Reproduce
Create a script like the below and run in mypy. Even though it's valid use of series.dtype.kind, it reports errors.

import pandas as pd
s1 = pd.Series(['foo'], dtype='string')
s2 = pd.Series([1], dtype='Int64')
print(s1.dtype.kind == 'O')
print(s2.dtype.kind == 'i')

Please complete the following information:

  • OS: Windows
  • OS Version 10
  • python version 3.8
  • version of type checker 0.971
  • version of installed pandas-stubs1.4.3.220724

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions