11
11
from typing import Sequence
12
12
from typing import TypeVar
13
13
from typing import overload
14
+ from warnings import warn
14
15
15
16
from narwhals .dependencies import get_polars
16
17
from narwhals .dependencies import is_numpy_array
17
18
from narwhals .schema import Schema
18
19
from narwhals .translate import to_native
20
+ from narwhals .utils import find_stacklevel
19
21
from narwhals .utils import flatten
20
22
from narwhals .utils import is_sequence_but_not_str
21
23
from narwhals .utils import parse_version
@@ -2865,7 +2867,7 @@ def pivot(
2865
2867
"min" , "max" , "first" , "last" , "sum" , "mean" , "median" , "len"
2866
2868
]
2867
2869
| None = None ,
2868
- maintain_order : bool = True ,
2870
+ maintain_order : bool | None = None ,
2869
2871
sort_columns : bool = False ,
2870
2872
separator : str = "_" ,
2871
2873
) -> Self :
@@ -2881,11 +2883,12 @@ def pivot(
2881
2883
specified on `on` and `index` will be used. At least one of `index` and
2882
2884
`values` must be specified.
2883
2885
aggregate_function: Choose from:
2886
+
2884
2887
- None: no aggregation takes place, will raise error if multiple values
2885
2888
are in group.
2886
2889
- A predefined aggregate function string, one of
2887
2890
{'min', 'max', 'first', 'last', 'sum', 'mean', 'median', 'len'}
2888
- maintain_order: Sort the grouped keys so that the output order is predictable .
2891
+ maintain_order: Has no effect and is kept around only for backwards-compatibility .
2889
2892
sort_columns: Sort the transposed columns by name. Default is by order of
2890
2893
discovery.
2891
2894
separator: Used as separator/delimiter in generated column names in case of
@@ -2933,14 +2936,19 @@ def pivot(
2933
2936
if values is None and index is None :
2934
2937
msg = "At least one of `values` and `index` must be passed"
2935
2938
raise ValueError (msg )
2939
+ if maintain_order is not None :
2940
+ msg = (
2941
+ "`maintain_order` has no effect and is only kept around for backwards-compatibility. "
2942
+ "You can safely remove this argument."
2943
+ )
2944
+ warn (message = msg , category = UserWarning , stacklevel = find_stacklevel ())
2936
2945
2937
2946
return self ._from_compliant_dataframe (
2938
2947
self ._compliant_frame .pivot (
2939
2948
on = on ,
2940
2949
index = index ,
2941
2950
values = values ,
2942
2951
aggregate_function = aggregate_function ,
2943
- maintain_order = maintain_order ,
2944
2952
sort_columns = sort_columns ,
2945
2953
separator = separator ,
2946
2954
)
0 commit comments