-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Bar plot from Series with IntervalIndex fails in pandas 1.2.0 #38969
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
Comments
Thanks @venaturum for the report - could you put a descriptive title too please? Also, show the full traceback, not just the final part with the error message? |
@MarcoGorelli , done now, sorry about that! @jorisvandenbossche, I think you're right, looks especially similar to 38947. |
both these fail from could close as duplicate or leave open to ensure additional test coverage |
(let's keep open until we actually fix + add a test for this specific case) |
No problem, I thought the closing candidate tag might have been a subtle hint 😂 |
Could anyone please clarify what's needed here? Are we only missing a regression test? I'd be happy to help with this issue. |
Yes, that's right |
Thank you @MarcoGorelli! In that case, I'll take this issue and start to work on it as soon as I can. |
To ensure this issue is assigned to me: take. |
@simonjayhawkins, @mroeschke, @MarcoGorelli: I left a comment above with the keyword 'take' but this issue was not assigned to me. Am I missing some step? Could any of you please assign it to me? Thanks! |
the comment should only have a single word: take if your comment includes other words, it won't work |
I see. Thanks! |
take |
take |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
The following error is raised in pandas 1.2.0
TypeError: Cannot cast IntervalIndex to dtype int32
pandas 1.1.5 does not have the same issue
stack trace:
TypeError Traceback (most recent call last)
c:\users\rclement\documents.venv\lib\site-packages\pandas\core\arrays\interval.py in astype(self, dtype, copy)
777 try:
--> 778 return np.asarray(self).astype(dtype, copy=copy)
779 except (TypeError, ValueError) as err:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'pandas._libs.interval.Interval'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
in
1 pd.Series(
2 [1,2],
----> 3 index=pd.interval_range(0,2)
4 ).plot.bar()
c:\users\rclement\documents.venv\lib\site-packages\pandas\plotting_core.py in bar(self, x, y, **kwargs)
1111 other axis represents a measured value.
1112 """
-> 1113 return self(kind="bar", x=x, y=y, **kwargs)
1114
1115 @appender(
c:\users\rclement\documents.venv\lib\site-packages\pandas\plotting_core.py in call(self, *args, **kwargs)
953 data.columns = label_name
954
--> 955 return plot_backend.plot(data, kind=kind, **kwargs)
956
957 call.doc = doc
c:\users\rclement\documents.venv\lib\site-packages\pandas\plotting_matplotlib_init_.py in plot(data, kind, **kwargs)
59 kwargs["ax"] = getattr(ax, "left_ax", ax)
60 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 61 plot_obj.generate()
62 plot_obj.draw()
63 return plot_obj.result
c:\users\rclement\documents.venv\lib\site-packages\pandas\plotting_matplotlib\core.py in generate(self)
278 self._compute_plot_data()
279 self._setup_subplots()
--> 280 self._make_plot()
281 self._add_table()
282 self._make_legend()
c:\users\rclement\documents.venv\lib\site-packages\pandas\plotting_matplotlib\core.py in _make_plot(self)
1432 if self.orientation == "vertical":
1433 ax.xaxis.update_units(self.ax_index)
-> 1434 self.tick_pos = ax.convert_xunits(self.ax_index).astype(np.int)
1435 elif self.orientation == "horizontal":
1436 ax.yaxis.update_units(self.ax_index)
c:\users\rclement\documents.venv\lib\site-packages\pandas\core\indexes\interval.py in astype(self, dtype, copy)
368 def astype(self, dtype, copy: bool = True):
369 with rewrite_exception("IntervalArray", type(self).name):
--> 370 new_values = self._values.astype(dtype, copy=copy)
371 return Index(new_values, dtype=new_values.dtype, name=self.name)
372
c:\users\rclement\documents.venv\lib\site-packages\pandas\core\arrays\interval.py in astype(self, dtype, copy)
779 except (TypeError, ValueError) as err:
780 msg = f"Cannot cast {type(self).name} to dtype {dtype}"
--> 781 raise TypeError(msg) from err
782
783 def equals(self, other) -> bool:
TypeError: Cannot cast IntervalIndex to dtype int32
Expected Output
A bar plot (produced with pandas 1.1.5):

Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 3e89b4c
python : 3.7.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.2.0
numpy : 1.19.4
pytz : 2020.5
dateutil : 2.8.1
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: