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

NameError: name '_converter' is not defined #19810

Closed
whitequark opened this Issue Feb 21, 2018 · 10 comments

Comments

Projects
None yet
6 participants
@whitequark

whitequark commented Feb 21, 2018

Code Sample, a copy-pastable example if possible

import pandas
d = pandas.DataFrame({"lat": [-6.081690, -5.207080], "lon": [145.789001, 145.391998]})
d.plot(kind='scatter', x='lat', y='lon')

Problem description

NameError                                 Traceback (most recent call last)
<ipython-input-4-f42fef061f30> in <module>()
      1 import pandas
      2 d = pandas.DataFrame({"lat": [-6.081690, -5.207080], "lon": [145.789001, 145.391998]})
----> 3 d.plot(kind='scatter', x='lat', y='lon')

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2675                           fontsize=fontsize, colormap=colormap, table=table,
   2676                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677                           sort_columns=sort_columns, **kwds)
   2678     __call__.__doc__ = plot_frame.__doc__
   2679 

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   1900                  yerr=yerr, xerr=xerr,
   1901                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902                  **kwds)
   1903 
   1904 

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1685         if isinstance(data, DataFrame):
   1686             plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1687                              kind=kind, **kwds)
   1688         else:
   1689             raise ValueError("plot kind %r can only be used for data frames"

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
    835             # the handling of this argument later
    836             s = 20
--> 837         super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
    838         if is_integer(c) and not self.data.columns.holds_integer():
    839             c = self.data.columns[c]

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
    802 
    803     def __init__(self, data, x, y, **kwargs):
--> 804         MPLPlot.__init__(self, data, **kwargs)
    805         if x is None or y is None:
    806             raise ValueError(self._kind + ' requires and x and y column')

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, kind, by, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, fig, title, xlim, ylim, xticks, yticks, sort_columns, fontsize, secondary_y, colormap, table, layout, **kwds)
     98                  table=False, layout=None, **kwds):
     99 
--> 100         _converter._WARN = False
    101         self.data = data
    102         self.by = by

NameError: name '_converter' is not defined

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.0-3-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.1
Cython: None
numpy: 1.14.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@whitequark

This comment has been minimized.

whitequark commented Feb 21, 2018

This is caused by the lack of matplotlib:

>>> from pandas.plotting import _converter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/whitequark/.local/lib/python3.6/site-packages/pandas/plotting/_converter.py", line 8, in <module>
    import matplotlib.units as units
ModuleNotFoundError: No module named 'matplotlib'

The error should be more useful.

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Feb 21, 2018

So this is a duplicate of #19340, and the problem is that we cannot reproduce it. It clearly shows up for multiple people, but we need to diagnose why this happens.

Can you run the code in #19340 (comment) and check if that fails?

@whitequark

This comment has been minimized.

whitequark commented Feb 21, 2018

Sure:

>>> from pandas.plotting._misc import (scatter_matrix, radviz,
...                                    andrews_curves, bootstrap_plot,
...                                    parallel_coordinates, lag_plot,
...                                    autocorrelation_plot)
>>> from pandas.plotting._core import boxplot
>>> from pandas.plotting._style import plot_params
>>> from pandas.plotting._tools import table
>>>
>>> from pandas.plotting._converter import \
...     register as register_matplotlib_converters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/whitequark/.local/lib/python3.6/site-packages/pandas/plotting/_converter.py", line 8, in <module>
    import matplotlib.units as units
ModuleNotFoundError: No module named 'matplotlib'
>>> from pandas.plotting._converter import \
...     deregister as deregister_matplotlib_converters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/whitequark/.local/lib/python3.6/site-packages/pandas/plotting/_converter.py", line 8, in <module>
    import matplotlib.units as units
ModuleNotFoundError: No module named 'matplotlib'
@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Feb 21, 2018

Ah, I actually can reproduce this, and I suppose this is due to

try:
from pandas.plotting import _converter
except ImportError:
pass
else:
if get_option('plotting.matplotlib.register_converters'):
_converter.register(explicit=True)

where we import _converter, which is later on used in the file, but then don't raise a good error message when matplotlib is not available.

Yes, this should certainly be solved.

@tonyshare

This comment has been minimized.

tonyshare commented Mar 3, 2018

I am also got the same error when learn the google pandas course.
I am using python3.6
and the computer system is mac osx 11

>>> import pandas as pd
>>> pd.__version__
'0.22.0'
>>> california_housing_dataframe = pd.read_csv("https://storage.googleapis.com/ml_universities/california_housing_train.csv", sep=",")
>>> california_housing_dataframe.head()
   longitude  latitude  housing_median_age  total_rooms  total_bedrooms  \
0    -114.31     34.19                15.0       5612.0          1283.0   
1    -114.47     34.40                19.0       7650.0          1901.0   
2    -114.56     33.69                17.0        720.0           174.0   
3    -114.57     33.64                14.0       1501.0           337.0   
4    -114.57     33.57                20.0       1454.0           326.0   

   population  households  median_income  median_house_value  
0      1015.0       472.0         1.4936             66900.0  
1      1129.0       463.0         1.8200             80100.0  
2       333.0       117.0         1.6509             85700.0  
3       515.0       226.0         3.1917             73400.0  
4       624.0       262.0         1.9250             65500.0  
>>> california_housing_dataframe.hist('housing_median_age')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2160, in hist_frame
    _converter._WARN = False
NameError: name '_converter' is not defined
@megaserg

This comment has been minimized.

megaserg commented Mar 4, 2018

Experienced this in Jupyter Notebook. Installed matplotlib, imported it, and reimported pandas afterwards, the exception did not go away. Restarted the notebook, and it was fixed. Feels like some global state doesn't get reinitialized.

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Mar 4, 2018

Experienced this in Jupyter Notebook. Installed matplotlib, imported it, and reimported pandas afterwards, the exception did not go away. Restarted the notebook, and it was fixed. Feels like some global state doesn't get reinitialized.

@megaserg to reliably check imports with python you always need to restart the python process.
But anyway, this is a bug, and we have to fix it for the next release.

@Ako520

This comment has been minimized.

Ako520 commented Apr 7, 2018

@tonyshare I met the same question, how do you solve?

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Apr 9, 2018

@Ako520 By installing matplotlib. This will be fixed in the next version of pandas.

jorisvandenbossche added a commit that referenced this issue Apr 9, 2018

@neo01124

This comment has been minimized.

neo01124 commented Apr 17, 2018

Solution is to restart the kernel or restarting jupyter server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment