# Trouble with vtkPythonAlgorithm

**URL:** https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992
**Category:** ParaView Support
**Created:** [February 16, 2022, 10:50pm UTC](https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992 "2022-02-16T22:50:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 16, 2022, 10:50pm UTC](https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992/1 "2022-02-16T22:50:00Z")

</div>

I’m having trouble reproducing the vtkPythonAlgorithm example from here:  
[4. Programmable Filter — ParaView Documentation 5.10.0 documentation](https://docs.paraview.org/en/v5.10.0/ReferenceManual/pythonProgrammableFilter.html#python-algorithm)

The plugin appears to load correctly, and I can control the output data type, but the resulting data object is empty. I tested this on a Wavelet source, using 5.10.0 and 5.9.1. Can anyone help me understand what is going on?

```auto
# setup the data processing pipelines
# ----------------------------------------------------------------

# create a new 'Wavelet'
wavelet1 = Wavelet(registrationName='Wavelet1')

# create a new 'Calculator'
calculator1 = Calculator(registrationName='Calculator1', Input=wavelet1)
calculator1.ResultArrayName = 'V'
calculator1.Function = 'RTData'

# create a new 'Half-V Filter'
halfVFilter1 = HalfVFilter(registrationName='HalfVFilter1', Input=calculator1)

```

The plugin source:

```auto
from vtkmodules.vtkCommonDataModel import vtkDataSet
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtkmodules.numpy_interface import dataset_adapter as dsa

# new module for ParaView-specific decorators.
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain

@smproxy.filter(label="Half-V Filter")
@smproperty.input(name="Input")
class HalfVFilter(VTKPythonAlgorithmBase):
    # the rest of the code here is unchanged.
    def __init__ (self):
        VTKPythonAlgorithmBase. __init__ (self, outputType='vtkImageData')

    def RequestData(self, request, inInfo, outInfo):
        # get the first input.
        input0 = dsa.WrapDataObject(vtkDataSet.GetData(inInfo[0]))

        # compute a value.
        data = input0.PointData["V"] / 2.0

        # add to output
        output = dsa.WrapDataObject(vtkDataSet.GetData(outInfo))
        output.PointData.append(data, "V_half");
        return 1

```

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [February 17, 2022, 8:25am UTC](https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992/2 "2022-02-17T08:25:02Z")

</div>

In the plugin code, the output is not initialized… You should add a `ShallowCopy` in RequestData:

```auto
output = dsa.WrapDataObject(vtkDataSet.GetData(outInfo))
output.ShallowCopy(input0.VTKObject)
output.PointData.append(data, "V_half")

```

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 17, 2022, 3:42pm UTC](https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992/3 "2022-02-17T15:42:57Z")

</div>

That did it. The documentation on the website should be corrected.

Thanks!

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [February 17, 2022, 8:52pm UTC](https://discourse.paraview.org/t/trouble-with-vtkpythonalgorithm/8992/4 "2022-02-17T20:52:48Z")

</div>

Documentation update happening here: [https://gitlab.kitware.com/paraview/paraview-docs/-/merge\_requests/30](https://gitlab.kitware.com/paraview/paraview-docs/-/merge_requests/30)
