Skip to content

Commit

Permalink
Fix duplicate entries in continuum line list (#2443)
Browse files Browse the repository at this point in the history
* Workaround list access

* Formatting

* Added error if duplicate

* Remove duplicates

* Fix typo, add comment

* Remove bandaid fix

* Cleanup

* More cleanup
  • Loading branch information
AlexHls committed Oct 13, 2023
1 parent ecd011c commit d2b0306
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tardis/plasma/properties/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit d2b0306

Please sign in to comment.