From d2b03068c12db73b98220f172bb67d72d8c5f982 Mon Sep 17 00:00:00 2001 From: Alexander Holas <70367168+AlexHls@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:48:04 +0200 Subject: [PATCH] Fix duplicate entries in continuum line list (#2443) * Workaround list access * Formatting * Added error if duplicate * Remove duplicates * Fix typo, add comment * Remove bandaid fix * Cleanup * More cleanup --- tardis/plasma/properties/atomic.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tardis/plasma/properties/atomic.py b/tardis/plasma/properties/atomic.py index 236edb01ecc..6ade1ae1377 100644 --- a/tardis/plasma/properties/atomic.py +++ b/tardis/plasma/properties/atomic.py @@ -467,6 +467,26 @@ def calculate(self, atomic_data): level_idxs2line_idx = pd.Series( np.arange(len(index)), index=index, name="lines_idx" ) + + # Check for duplicate indices + if level_idxs2line_idx.index.duplicated().any(): + logger.warn( + "Duplicate indices in level_idxs2line_idx. " + "Dropping duplicates. " + "This is an issue with the atomic data & carsus. " + "Once fixed upstream, this warning will be removed. " + "This will raise an error in the future instead. " + "See https://github.com/tardis-sn/carsus/issues/384" + ) + # This is necessary since pd.DataFrame.drop_duplicates() + # does not remove duplicates if the data is different + # and only the index is duplicated. See the example given + # in the pandas documentation: + # https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.drop_duplicates.html + level_idxs2line_idx = level_idxs2line_idx[ + ~level_idxs2line_idx.index.duplicated() + ] + return level_idxs2line_idx