Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-39368: Check for type before sorting #140

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions python/lsst/analysis/tools/actions/plot/plotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from lsst.geom import Box2D, SpherePoint, degrees
from lsst.pex.config import Config, Field
from matplotlib import colors
Expand Down Expand Up @@ -384,21 +385,26 @@ def sortAllArrays(arrsToSort, sortArrayIndex=0):

Parameters
----------
arrsToSort : `list` [`np.array`]
A list of arrays to be simultaneously sorted based on the array in
the list position given by ``sortArrayIndex`` (defaults to be the
first array in the list).
arrsToSort : `list` [`np.array`] | `list` [`pd.Series`]
A list of arrays or Series to be simultaneously sorted based on the
array in the list position given by ``sortArrayIndex`` (defaults to be
the first array in the list).
sortArrayIndex : `int`, optional
Zero-based index indicating the array on which to base the sorting.

Returns
-------
arrsToSort : `list` [`np.array`]
The list of arrays sorted on array in list index ``sortArrayIndex``.
arrsToSort : `list` [`np.array`] | `list` [`pd.Series`]
The list of arrays or Series (same type as the input) sorted on array
in list index ``sortArrayIndex``.
"""
ids = extremaSort(arrsToSort[sortArrayIndex])
for i, arr in enumerate(arrsToSort):
arrsToSort[i] = arr[ids]
if isinstance(arr, pd.Series):
arrsToSort[i] = arr.iloc[ids]
else:
arrsToSort[i] = arr[ids]

return arrsToSort


Expand Down
Loading