BUG: lib.infer_type broken for IntervalArray / PeriodArray
See original GitHub issueWhile working on #23167, I found a regression in IntervalArray / PeriodArray - I’m guessing it’s related to the whole EA effort. @jorisvandenbossche @TomAugspurger
>>> import pandas as pd
>>> import pandas._libs.lib as lib
>>> s = pd.Series([pd.Period(2013), pd.Period(2018)], dtype='category')
>>> lib.infer_dtype(s.values.categories)
Traceback (most recent call last):
File "pandas\_libs\lib.pyx", line 1166, in pandas._libs.lib.infer_dtype
values = getattr(value, '_values', getattr(value, 'values', value))
TypeError: Cannot convert PeriodArray to numpy.ndarray
>>>
>>> t = pd.Series([pd.Interval(0, 1), pd.Interval(0, 2)], dtype='category')
>>> lib.infer_dtype(t.values.categories)
Traceback (most recent call last):
File "pandas\_libs\lib.pyx", line 1166, in pandas._libs.lib.infer_dtype
values = getattr(value, '_values', getattr(value, 'values', value))
TypeError: Cannot convert IntervalArray to numpy.ndarray
This was still working in v0.23.4
:
>>> import pandas as pd
>>> import pandas._libs.lib as lib
>>> pd.__version__
'0.23.4'
>>> s = pd.Series([pd.Period(2013), pd.Period(2018)], dtype='category')
>>> lib.infer_dtype(s.values.categories)
'period'
>>>
>>> t = pd.Series([pd.Interval(0, 1), pd.Interval(0, 2)], dtype='category')
>>> lib.infer_dtype(t.values.categories)
'interval'
This is due to the fact that lib.infer_dtype
tries
values = getattr(value, '_values', getattr(value, 'values', value))
and both IntervalArray
/ PeriodArray
do not return a numpy array for _values
anymore. For PeriodArray
, it would work if _values
and values
were switched, but for IntervalArray
, both _values
and values
return the same (non-numpy-array) result.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Yup InferType for array of strings not working as expected
I'm trying to use Yup to define a schema and generate a Typescript Type that I can use for my objects. Using InferType...
Read more >pandas.arrays.IntervalArray — pandas 1.5.2 documentation
Array-like containing Interval objects from which to build the IntervalArray. Whether the intervals are closed on the left-side, right-side, both or neither. ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
milestone ping pong, haha. 😉
Would this still be acceptable during RC phase? I might be able to make some time.
i think we could eventually add those but the inference is used in indexing so i am not sure if changing it now would work