question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: lib.infer_type broken for IntervalArray / PeriodArray

See original GitHub issue

While 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:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
h-vetinaricommented, Jan 9, 2019

milestone ping pong, haha. 😉

Would this still be acceptable during RC phase? I might be able to make some time.

0reactions
jrebackcommented, Nov 10, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found