Skip to content

API/DOC: types covered by lib.infer_dtype #23554

Open
@h-vetinari

Description

@h-vetinari

In #23167, I'm trying consistently infer the dtype of the underlying Series/Index while calling the constructor of the .str-accessor. For testing this thoroughly, I wanted to build a parametrized fixture that returns an ndarray for all the dtypes that lib.infer_dtype can infer. I based myself on the list in the docstring, but found the following:

  • the docstring mentions 'complex' as a possible outcome, but this does not work (instead returning 'mixed')
>>> lib.infer_dtype([1+1j, 2+2j])
'mixed'
>>> lib.infer_dtype([np.complex128(1+1j)])
'mixed'

and I don't believe it's actually possible to achieve this, given the code.

  • the docstring mentions 'timedelta64', but this similarly does not work (returning 'timedelta'; and can't be hit either, IMO)
>>> lib.infer_dtype([np.timedelta64(1, 'D')])
'timedelta'
  • the docstring does not mention 'interval', but that is a possible outcome:
>>> lib.infer_dtype([pd.Interval(0, 1), pd.Interval(0, 2)])
'interval'

So it needs to be discussed if 'complex'/'timedelta64' should be added to the code or removed from the docstring, and vice versa for 'interval'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsDtype ConversionsUnexpected or buggy dtype conversionsNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions