soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
453 stars 132 forks source link

Pandas ValueError when calling subtract_drift #734

Open kevin-duclos opened 1 year ago

kevin-duclos commented 1 year ago

Running motion.subtract_drift sometimes produces the error below, depending on the data. Possibly related to issue #730.

/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/trackpy/motion.py:315: FutureWarning: reindexing with a non-unique Index is deprecated and will raise in a future version.
  traj[col] = traj[col].sub(drift[col], fill_value=0, level='frame')
Traceback (most recent call last):
  File "/Users/kevinadmin/Work/Code/pythons/diatom-sinking-processing/main.py", line 231, in <module>
    main(filepath_seq)
  File "/Users/kevinadmin/Work/Code/pythons/diatom-sinking-processing/main.py", line 147, in main
    traj_minus_drift = tp.subtract_drift(traj=traj, drift=drift_sub)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/trackpy/motion.py", line 315, in subtract_drift
    traj[col] = traj[col].sub(drift[col], fill_value=0, level='frame')
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/frame.py", line 3980, in __setitem__
    self._set_item(key, value)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/frame.py", line 4174, in _set_item
    value = self._sanitize_column(value)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/frame.py", line 4912, in _sanitize_column
    return _reindex_for_setitem(Series(value), self.index)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/frame.py", line 12025, in _reindex_for_setitem
    raise err
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/frame.py", line 12020, in _reindex_for_setitem
    reindexed_value = value.reindex(index)._values
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/series.py", line 5094, in reindex
    return super().reindex(**kwargs)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/generic.py", line 5289, in reindex
    return self._reindex_axes(
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/generic.py", line 5309, in _reindex_axes
    obj = obj._reindex_with_indexers(
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/generic.py", line 5355, in _reindex_with_indexers
    new_data = new_data.reindex_indexer(
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/internals/managers.py", line 737, in reindex_indexer
    self.axes[axis]._validate_can_reindex(indexer)
  File "/Users/kevinadmin/miniconda3/envs/trackpy/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 4316, in _validate_can_reindex
    raise ValueError("cannot reindex on an axis with duplicate labels")
ValueError: cannot reindex on an axis with duplicate labels
kevin-duclos commented 1 year ago

Associated pull request: #735