Skip to content

Commit

Permalink
check lexsort in the 'lazy_sort_index' function (#566)
Browse files Browse the repository at this point in the history
* check lexsort

* check lexsort

* lexsort comment

* lexsort comment
  • Loading branch information
markzhao98 committed Aug 25, 2021
1 parent 1158472 commit 25b771d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion qlib/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ def lazy_sort_index(df: pd.DataFrame, axis=0) -> pd.DataFrame:
sorted dataframe
"""
idx = df.index if axis == 0 else df.columns
if idx.is_monotonic_increasing:
# NOTE: MultiIndex.is_lexsorted() is a deprecated method in Pandas 1.3.0 and is suggested to be replaced by MultiIndex.is_monotonic_increasing (see discussion here: https://github.com/pandas-dev/pandas/issues/32259). However, in case older versions of Pandas is implemented, MultiIndex.is_lexsorted() is necessary to prevent certain fatal errors.
if idx.is_monotonic_increasing and not (isinstance(idx, pd.MultiIndex) and not idx.is_lexsorted()):
return df
else:
return df.sort_index(axis=axis)
Expand Down

0 comments on commit 25b771d

Please sign in to comment.