updatePipeline of programmable filter overwriting the max function

first of all i must say that i was able to pinpoint this issue thanks to LLM.
my code was working correctly when using paraview/python shell and running my code but when i was running it with pvbatch i was getting an error of the max() function not having the default input. this went thought a rabbit hole of ‘I am importing with wild cards, but this has been always worked etc etc’
and at the end i was able to pin point it when doing the pudate of the programmable filter.

import builtins

def checkMax(label):

print(f"{label}: {max} | built-in={max is builtins.max}",flush=True)

checkMax("13a")

self.programmableFilter.UpdatePipeline()

checkMax("13b")

which i was getting:

13a: <built-in function max> | built-in=True
13b: <function max at 0x7c527d068b80> | built-in=False

I made a small script that can reproduce this issue:

from paraview.simple import *
import builtins

print("BEFORE:",max)
print("BEFORE is builtins.max:",max is builtins.max)

# Create a simple input
sphere=Sphere()

# Create a Programmable Filter similar to yours
programmableFilter=ProgrammableFilter(Input=sphere)

script="""
import numpy as np
inputData=inputs[0]
output=self.GetOutput()
output.ShallowCopy(inputData.VTKObject)
"""

programmableFilter.Script=script

print("BEFORE UpdatePipeline:",max)
print("BEFORE is builtins.max:",max is builtins.max)

programmableFilter.UpdatePipeline()

print("AFTER UpdatePipeline:",max)
print("AFTER is builtins.max:",max is builtins.max)

# Test Python's max(default=...)
try:
    result=max([],default=-1)
    print("max works:",result)
except Exception as e:
    print("max FAILED:",type(e).__name__,e)

I am getting a reproductable result:

BEFORE: <built-in function max>
BEFORE is builtins.max: True
BEFORE UpdatePipeline: <built-in function max>
BEFORE is builtins.max: True
AFTER UpdatePipeline: <function max at 0x71ec97372200>
AFTER is builtins.max: False
max FAILED: TypeError max() got an unexpected keyword argument 'default'

which is quite strange… :sweat_smile: (at least for me)
this happens to me with pvbatch and pvpython

Indeed, I reproduce on the dev branch of ParaView!

Adding

except Exception as e:
   help(max)

Points the faulty ParaView module that override it

paraview.vtk.numpy_interface.algorithms

Definitely an issue, can you open a ticket please?

created https://gitlab.kitware.com/paraview/paraview/-/work_items/23382
crazy bug that had not bitten some persons before now to be found…

People have run into related issues before:

I’m not saying it’s great to have to do, but to be safe use builtins.max when you want the builtin max.

yeah it is what i am actually doing, specially that i was using max in other situations where the numpy version was not working at all. but i am surprised that the post you cited is from 2000s, i have been reporting a lot of small bugs here and there (i use quite strangelly paraview and have a strange logic on my head so i have tendency of finding small bugs around, the folks at salome are tired of hearing about my github issues ahahah). but this one could be quite big as one would be using a different library which could be different results… i guess most of the time one uses max/min in classing array/list situation giving same result, but there might be some more complex functions where this could impact. one is thinking it is using something but it is using something else without much ‘knowledge’ about