Skip to content
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

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

Open
h-vetinari opened this issue Nov 7, 2018 · 3 comments
Open

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

h-vetinari opened this issue Nov 7, 2018 · 3 comments
Labels
Docs Dtype Conversions Unexpected or buggy dtype conversions Needs Discussion Requires discussion from core team before further action

Comments

@h-vetinari
Copy link
Contributor

h-vetinari commented Nov 7, 2018

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'.

@h-vetinari
Copy link
Contributor Author

@TomAugspurger
Pinging you here as this is related to #23553 and may be related to #23581

@TomAugspurger
Copy link
Contributor

I haven't been able to wrap my head around infer_dtype yet, but adding interval seems fine.

but this similarly does not work (returning 'timedelta'; and can't be hit either, IMO)


In [25]: lib.infer_dtype(list(np.array([1], dtype='timedelta64[ns]'))[0])
Out[25]: 'timedelta64'

In [26]: lib.infer_dtype(list(np.array([1], dtype='timedelta64[ns]')))
Out[26]: 'timedelta'

Out[26] looks like a bug.

FWIW, rewriting the Series constructor is on my medium-term todo list, but not before 0.24 is done. Part of that would be a cleanup of infer_dtype.

@h-vetinari
Copy link
Contributor Author

Discovered a relevant usage of the timedelta/timedelta64 case:
pandas.core.dtypes.cast.maybe_downcast_to_dtype explicitly tests the inferred dtype for equality to 'timedelta64', but not 'timedelta'.

@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed API Design labels Jun 23, 2021
MichaelTiemannOSC added a commit to MichaelTiemannOSC/pandas that referenced this issue Aug 5, 2023
complex numbers now appear to work for GH pandas-dev#23554.

There are no examples as to how to update the whatsnew documentation for conftest.py, so I don't know whether or how to add an entry for this change.

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
mroeschke pushed a commit that referenced this issue Aug 5, 2023
complex numbers now appear to work for GH #23554.

There are no examples as to how to update the whatsnew documentation for conftest.py, so I don't know whether or how to add an entry for this change.

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
mroeschke pushed a commit to mroeschke/pandas that referenced this issue Aug 18, 2023
complex numbers now appear to work for GH pandas-dev#23554.

There are no examples as to how to update the whatsnew documentation for conftest.py, so I don't know whether or how to add an entry for this change.

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Dtype Conversions Unexpected or buggy dtype conversions Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

4 participants