You'll have to test for the type, or use exception handling, to switch approaches:

def find_max(a):
    if isinstance(a, list):
        return max(list)
    return a.values.max()

or

def find_max(a):
    try:
        return a.values.max()
    except AttributeError:
        # assume a Python sequence
        return max(a)

Which one you pick depends on a few factors:

  • Do you need to support other iterables, like tuples or sets or generators?
  • What is the more common case; the try...except case is faster if the majority of calls pass in a Pandas series.

Another option is to use np.max(), which works on either type:

import numpy as np

def find_max(a):
    return np.max(a)

Note that there is no need to use the .values attribute here!

Answer from Martijn Pieters on Stack Overflow
🌐
Real Python
realpython.com › numpy-max-maximum
NumPy's max() and maximum(): Find Extreme Values in Arrays – Real Python
January 18, 2025 - In this section, you’ll become familiar with np.max(), a versatile tool for finding maximum values in various circumstances. Note: NumPy has both a package-level function and an ndarray method named max(). They work in the same way, though the package function np.max() requires the target array name as its first parameter. In what follows, you’ll be using the function and the method interchangeably. Python also has a built-in max() function that can calculate maximum values of iterables.
🌐
W3Schools
w3schools.com › python › ref_func_max.asp
Python max() Function
Python Examples Python Compiler ... Python Certificate Python Training ... The max() function returns the item with the highest value, or the item with the highest value in an iterable....
🌐
Tutorialspoint
tutorialspoint.com › python › list_max.htm
Python List max() Method
print("Max value element : ", str(max(list1))) TypeError: '>' not supported between instances of 'str' and 'int'
🌐
Educative
educative.io › answers › how-to-find-the-largest-element-in-an-array-in-python
How to find the largest element in an array in Python
If it is, then assign the value in i to the variable largest. After the loop ends, largest will store the largest element in the list. ... We will use Python’s built-in function max() to solve this problem.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-find-largest-element-in-an-array
Python Program to Find Largest Element in an Array - GeeksforGeeks
October 22, 2025 - Given an array, we need to find the largest element in it. ... Python has an inbuilt method max() which returns the maximum value among the arguments.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › max
Python Numpy max() - Find Maximum Value | Vultr Docs
November 18, 2024 - Create a one-dimensional NumPy array. Use max() to find the maximum value.
🌐
BinaryFish
binary-fish.vercel.app › blog › pythonmaxmin
How to get max and min value of an array in python.
January 8, 2024 - To get the maximum value of an array, you can use the max() function.
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.amax.html
numpy.amax — NumPy v2.4 Manual
numpy.amax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)[source]# Return the maximum of an array or maximum along an axis.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to calculate maximum of array in numpy
How to Calculate Maximum of Array in NumPy - Spark By {Examples}
September 24, 2024 - Python NumPy maximum() or max() function is used to get the maximum value (greatest value) of a given array, or compare the two arrays
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.max.html
numpy.max — NumPy v2.2 Manual
Maximum of a. If axis is None, the result is a scalar value. If axis is an int, the result is an array of dimension a.ndim - 1.
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.04-computation-on-arrays-aggregates.html
Aggregations: Min, Max, and Everything In Between | Python Data Science Handbook
In particular, their optional arguments have different meanings, and np.sum is aware of multiple array dimensions, as we will see in the following section. Similarly, Python has built-in min and max functions, used to find the minimum value and maximum value of any given array:
🌐
Programiz
programiz.com › python-programming › numpy › methods › max
NumPy max()
... The max() method returns the largest element of an array along an axis. import numpy as np array1 = np.array([10, 12, 14, 11, 5]) # return the largest element maxValue= np.max(array1) print(maxValue) # Output: 14 ... numpy.max(array, axis = None, out = None, keepdims = <no value>, initial=<no ...
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › maximum
Python Numpy maximum() - Find Maximum Value | Vultr Docs
November 18, 2024 - Initialize a NumPy array with numerical values. Apply numpy.maximum() to find the maximum value in the array.
🌐
Quora
quora.com › Is-there-a-built-in-function-in-Python-for-finding-the-maximum-value-in-an-array-If-so-how-does-it-work
Is there a built-in function in Python for finding the maximum value in an array? If so, how does it work? - Quora
The syntax is: max (array) [code]l = eval (input ('Enter an array: ')) print (max (l)) [/code]max () function iterates through the given array, and assigns the first-ever element as the ‘maximum value’...
🌐
HowToDoInJava
howtodoinjava.com › home › python examples › python max() and min(): find max and min in array
Python max() and min(): Find max and min in Array
September 21, 2023 - In this beginner-friendly guide, we’ll explore how to use max() and min() effectively. numbers = [3, 7, 1, 9, 4, 2] max_number = max(numbers) # 9 min_number = min(numbers) # 1 · The max() function finds the maximum value in an iterable.
🌐
DataCamp
datacamp.com › doc › numpy › max
NumPy max()
In this example, `np.max(array)` returns `7`, the maximum value in the entire one-dimensional array since no axis is specified.
🌐
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .max()
Python:NumPy | Built-in Functions | .max() | Codecademy
July 2, 2025 - The .max() function in NumPy returns the maximum value of an array or the maximum values along a specified axis. This function is essential for data analysis, statistical computations, and finding peak values in datasets.