importing dataset_adapter in PV 5.10

I’m having trouble importing dataset_adapter in PV 5.10 using either pvpython or the Python View in the GUI. This is with the installer-based version. I’m not a Python expert but it seems like a bad idea to have a Python module with dashes in it, i.e. pv-vtk-all.py. What I’m seeing in pvpython is:

>>> from paraview.vtk import dataset_adapter as DA
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'dataset_adapter' from 'paraview.pv-vtk-all' (/home/acbauer/Code/ParaView/ParaView-5.10.0-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/pv-vtk-all.py)

Am I doing something wrong here or is this a bug? I’m going with the directions from
https://www.paraview.org/Wiki/Python_Programmable_Filter

Using the directions at https://www.kitware.com/improved-vtk-numpy-integration-part-2/ it imports like:

from vtk.numpy_interface import dataset_adapter as dsa

This seems to be the proper way to do it now.

Thanks,
Andy

Dashes are implicitly discouraged in the PEP 8 guidelines, but their presence is not the cause of your issue.

That example is incorrect. I fixed it to use from paraview.vtk.numpy_interface import dataset_adapter as dsa. The example was missing the numpy_interface module. Note that you can also write from vtk.numpy_interface import dataset_adapter as dsa - either works fine.

For more background on importing vtk vs. paraview.vtk, please see this blog post. Basically, if you want anything available in VTK, you can write

import vtk

This imports all of VTK, so it will be slow, hence doing so is discouraged.

If you only need a subset of VTK for commonly used filters, you can write from paraview import vtk. This is faster to import, but may not import all the VTK classes you need.

For ultimate efficiency, you can import only the VTK classes you absolutely need with statements like

from vtkmodules.vtkFiltersCore import vtkSmoothPolyDataFilter

The downside is you need to identify in which module a VTK class exists, but that isn’t too hard.