pythongremlinamazon-neptunegremlinpythonneptune

Why is min(a,b) not working but max(a,b) working?


I’m writing a very simple Python code which requires the minimum of two integers, so when I do min(2,5) I get TypeError: 'Operator' object is not callable error. However, when I do max(2,5) I get the correct output. I am trying this in a cell in Python notebook with Python3. The code I'm trying to execute:

def split(node_list):
    k, m = divmod(len(node_list), 5)
    chunks = [node_list[i*quo+min(i, m):(i+1)*k+min(i+1, m)] for i in range(5)]
    return chunks

From my research, some posts mentioned not to have any other variables named "min". Initially I was confused because I had no other variable or function named "min". Then I realized the the file I'm using is also executing code using gremlin_python library that has min() in-built function which is used to query Neptune graphs, and that's probably why I'm seeing this error. Could someone please let me know how I could explicitly ensure that the code used Python's in-build min()? Is there any other way to resolve this issue?

Edit: Gremlin imports i'm using

from gremlin_python import statics
from gremlin_python.driver import serializer
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.aiohttp.transport import AiohttpTransport

Solution

  • Whenever a Gremlin Python step or function name collides with a Python reserved word, you can use an underscore after the function name. For example in gremlin Python you would use min_() .

    In earlier versions of the TinkerPop documentation it was suggested to do statics.load_statics(globals()) which actually can cause exactly the issues you encountered. I would avoid messing with statics and just use the Gremlin form with the underscores.