-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of Polars.
Reproducible example
import polars as pl
def function(s: pl.Series, a: int, b: int = 0) -> pl.Series:
return a * s + b
df = pl.DataFrame({"a": [1, 2]})
df.map_columns("a", function, 1, b=2)Log output
Issue description
The type hint for the function parameter in DataFrame.map_columns is currently Callable[[Series], Series]. However, the implementation of map_columns passes *args and **kwargs from the map_columns method directly to the function callable. This makes the current type hint incorrect and overly restrictive, as it implies the function only accepts a single Series argument.
To accurately reflect the function's usage, the type hint for function should be updated to Callable[Concatenate[Series, P], Series], where P is a ParamSpec capturing the *args and **kwargs passed to map_columns. This change would ensure that the type hint correctly indicates that the user-provided function can accept additional positional and keyword arguments.
Expected behavior
Type checkers (e.g., MyPy) should correctly recognize that the function parameter of DataFrame.map_columns can accept additional positional and keyword arguments (*args, **kwargs) after the initial Series argument. This ensures that custom functions passed to map_columns can be type-checked accurately when they utilize these additional arguments.
Installed versions
Details
--------Version info---------
Polars: 1.37.1
Index type: UInt32
Platform: Windows-11-10.0.26200-SP0
Python: 3.14.2 (main, Dec 9 2025, 19:03:14) [MSC v.1944 64 bit (AMD64)]
Runtime: rt32
----Optional dependencies----
Azure CLI <not installed>
adbc_driver_manager <not installed>
altair <not installed>
azure.identity <not installed>
boto3 <not installed>
cloudpickle <not installed>
connectorx <not installed>
deltalake <not installed>
fastexcel <not installed>
fsspec <not installed>
gevent <not installed>
google.auth <not installed>
great_tables <not installed>
matplotlib <not installed>
numpy <not installed>
openpyxl <not installed>
pandas <not installed>
polars_cloud <not installed>
pyarrow <not installed>
pydantic <not installed>
pyiceberg <not installed>
sqlalchemy <not installed>
torch <not installed>
xlsx2csv <not installed>
xlsxwriter <not installed>