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

Plotter does not render after Pandas.read_excel() is called in a Jupyter notebook #5895

Open
mdmelin opened this issue Apr 10, 2024 · 16 comments
Labels
bug Uh-oh! Something isn't working as expected.

Comments

@mdmelin
Copy link

mdmelin commented Apr 10, 2024

Describe the bug, what's wrong, and what you expected.

I was having difficulty getting a plot to show up inside a Jupyter notebook. The pyvista plotter was infinitely stuck on the loading message. I traced this back to using pd.read_excel() before trying to plot something. Commenting this out and restarting the kernel resolved the issue. I tried using pd.read_csv() and pd.read_excel() with an .xls file and it worked fine. It seems that the problem is restricted to the loading of .xlsx files.

The pandas version is 1.5.3

Steps to reproduce the bug.

This code must be run in a Jupyter notebook. It will not result in bugged behavior for a Python file.

import pandas as pd
import pyvista as pv
from pyvista import examples
from pathlib import Path

file = Path.home() / 'Downloads' / 'Financial Sample.xlsx' #any xlsx file
data = pd.read_excel(file) # comment this out and pyvista should plot fine
data = examples.download_saddle_surface()
data.plot(color='tan')

System Information

--------------------------------------------------------------------------------
  Date: Tue Apr 09 22:25:35 2024 Pacific Daylight Time

                  OS : Windows
              CPU(s) : 32
             Machine : AMD64
        Architecture : 64bit
                 RAM : 63.9 GiB
         Environment : Jupyter
          GPU Vendor : NVIDIA Corporation
        GPU Renderer : NVIDIA GeForce RTX 3080/PCIe/SSE2
         GPU Version : 4.5.0 NVIDIA 536.23
    MathText Support : False

  Python 3.10.12 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 19:01:18)
  [MSC v.1916 64 bit (AMD64)]

             pyvista : 0.43.3
                 vtk : 9.3.0
               numpy : 1.23.5
          matplotlib : 3.8.3
              scooby : 0.9.2
               pooch : 1.8.0
              pillow : 10.0.0
             imageio : 2.33.1
           pyvistaqt : 0.11.0
               PyQt5 : 5.15.10
             IPython : 8.15.0
            colorcet : 3.0.1
             cmocean : 3.1.3
          ipywidgets : 8.1.1
               scipy : 1.10.1
                tqdm : 4.66.1
              meshio : 5.3.5
          jupyterlab : 4.0.8
               trame : 3.5.2
        trame_client : 2.15.0
        trame_server : 2.16.0
           trame_vtk : 2.8.0
       trame_vuetify : 2.4.2
jupyter_server_proxy : 4.1.0
        nest_asyncio : 1.5.6
--------------------------------------------------------------------------------

Screenshots

pd_issue
@mdmelin mdmelin added the bug Uh-oh! Something isn't working as expected. label Apr 10, 2024
@mdmelin
Copy link
Author

mdmelin commented Apr 10, 2024

I've not contributed to PyVista before. But if it's helpful, I'm happy to take a crack at it if someone can point me in the right direction.

@darikg
Copy link
Contributor

darikg commented Apr 10, 2024

that's super weird. It looks like read_excel has an engine option, and openpyxl is used by default for xlsx files. Maybe check if just importing openpyxl without reading a file is enough to also break the plotter? Or check if the calamine engine also breaks it?

@mdmelin
Copy link
Author

mdmelin commented Apr 10, 2024

Looks like it may be related to the openpyxl engine like you suspected. import openpyxl is sufficient to reproduce the issue. Works fine with calamine. I upgraded to pandas 2.2.2 and the issue persists.

@mdmelin
Copy link
Author

mdmelin commented Apr 10, 2024

I also called the imports from the openpyxl __init__.py individually.

from openpyxl.compat.numbers import NUMPY
from openpyxl.xml import DEFUSEDXML, LXML
from openpyxl.workbook import Workbook
from openpyxl.reader.excel import load_workbook as open
from openpyxl.reader.excel import load_workbook
import openpyxl._constants as constants

Calling any one of these imports was sufficient sufficient to reproduce the issue.

@darikg
Copy link
Contributor

darikg commented Apr 11, 2024

I think any sort of from openpyxl import ... is equivalent to import openpyxl so it makes sense any one of those imports will cause the same problem. What about import lxml?

@mdmelin
Copy link
Author

mdmelin commented Apr 11, 2024

works fine with import lxml

@darikg
Copy link
Contributor

darikg commented Apr 12, 2024

I'm at a loss. It doesn't seem like openpyxl is really importing anything that could do this. What version of openpyxl do you have? I just installed 3.1.2 and am unable to replicate.

@tkoyama010
Copy link
Member

That's really weird.

@mdmelin
Copy link
Author

mdmelin commented Apr 12, 2024

Are you using the notebook backend @darikg? I created a new environment from scratch, and it does work with just pip install pyvista openpyxl. I get a warning saying that the notebook backend can't be used because trame is not installed, so I think that plot is not interactive. When I did pip install pyvista[jupyter] to get trame and the other backend components for Jupyter, the bug reappeared. I've attached a file with the environment needed for the bug to appear on my machine (pip install pandas pyvista[jupyter]).

bug_requirements.txt

@mdmelin
Copy link
Author

mdmelin commented Apr 12, 2024

I wondered if it was maybe related to me using a Notebook inside VSCode. I opened the notebook in Chrome and that didn't fix it either.

@darikg
Copy link
Contributor

darikg commented Apr 12, 2024

Yeah, in a new Windows python 3.11 environment, pip install -r bug_requirements.txt, jupyter lab in chrome,

import openpyxl
from pyvista import Sphere
Sphere().plot()

works fine 😕

@mdmelin
Copy link
Author

mdmelin commented Apr 12, 2024

What if you swap the import order? I have typically been importing openpyxl after pyvista.

@mdmelin
Copy link
Author

mdmelin commented Apr 12, 2024

I just ran your code and was still encountering this bug. So I guess the order doesn't matter for me. So strange. My Python version in this environment is 3.12.2. Otherwise I'm totally at a loss...

@darikg
Copy link
Contributor

darikg commented Apr 12, 2024

just checked python 3.12.2 for completeness' sake, and it's fine regardless of import order. you're on windows too? i'm willing to blame some sort of poltergeist at this point

@mdmelin
Copy link
Author

mdmelin commented Apr 13, 2024

Yeah Windows 10. Weird that I consistently have the issue in fresh environments. Maybe my anaconda installation is a bit messed up. Anyways if no one else can replicate it guess we should leave it alone for now.

@darikg
Copy link
Contributor

darikg commented Apr 14, 2024

Yeah sorry! I'm really curious what's causing this but don't have any ideas for further isolating it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

No branches or pull requests

3 participants