|
35 | 35 | from pandas.core.dtypes.common import is_dict_like, is_list_like
|
36 | 36 | from pandas.core.dtypes.generic import ABCDataFrame, ABCNDFrame, ABCSeries
|
37 | 37 |
|
| 38 | +from pandas.core.algorithms import safe_sort |
38 | 39 | from pandas.core.base import DataError, SpecificationError
|
39 | 40 | import pandas.core.common as com
|
40 | 41 | from pandas.core.indexes.api import Index
|
@@ -482,9 +483,10 @@ def transform_dict_like(
|
482 | 483 |
|
483 | 484 | if obj.ndim != 1:
|
484 | 485 | # Check for missing columns on a frame
|
485 |
| - cols = sorted(set(func.keys()) - set(obj.columns)) |
| 486 | + cols = set(func.keys()) - set(obj.columns) |
486 | 487 | if len(cols) > 0:
|
487 |
| - raise SpecificationError(f"Column(s) {cols} do not exist") |
| 488 | + cols_sorted = list(safe_sort(list(cols))) |
| 489 | + raise SpecificationError(f"Column(s) {cols_sorted} do not exist") |
488 | 490 |
|
489 | 491 | # Can't use func.values(); wouldn't work for a Series
|
490 | 492 | if any(is_dict_like(v) for _, v in func.items()):
|
@@ -738,7 +740,11 @@ def agg_dict_like(
|
738 | 740 | if isinstance(selected_obj, ABCDataFrame) and len(
|
739 | 741 | selected_obj.columns.intersection(keys)
|
740 | 742 | ) != len(keys):
|
741 |
| - cols = sorted(set(keys) - set(selected_obj.columns.intersection(keys))) |
| 743 | + cols = list( |
| 744 | + safe_sort( |
| 745 | + list(set(keys) - set(selected_obj.columns.intersection(keys))), |
| 746 | + ) |
| 747 | + ) |
742 | 748 | raise SpecificationError(f"Column(s) {cols} do not exist")
|
743 | 749 |
|
744 | 750 | from pandas.core.reshape.concat import concat
|
|
0 commit comments