From e4a70927873bdfc531dae100c7f835c0126ab3de Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Fri, 28 Jul 2023 10:39:00 -0700 Subject: [PATCH 1/2] Check for type before sorting --- python/lsst/analysis/tools/actions/plot/plotUtils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/lsst/analysis/tools/actions/plot/plotUtils.py b/python/lsst/analysis/tools/actions/plot/plotUtils.py index 305cdcb8c..08c73445a 100644 --- a/python/lsst/analysis/tools/actions/plot/plotUtils.py +++ b/python/lsst/analysis/tools/actions/plot/plotUtils.py @@ -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 @@ -398,7 +399,11 @@ def sortAllArrays(arrsToSort, sortArrayIndex=0): """ 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 From 046358dc8444b57dccf4df4a585c3e4d27de86e7 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Fri, 28 Jul 2023 11:24:38 -0700 Subject: [PATCH 2/2] fixup: docstring changes --- .../lsst/analysis/tools/actions/plot/plotUtils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/python/lsst/analysis/tools/actions/plot/plotUtils.py b/python/lsst/analysis/tools/actions/plot/plotUtils.py index 08c73445a..02f83082f 100644 --- a/python/lsst/analysis/tools/actions/plot/plotUtils.py +++ b/python/lsst/analysis/tools/actions/plot/plotUtils.py @@ -385,17 +385,18 @@ 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):