Skip to content

Commit

Permalink
TST: subtract_drift with no particle column
Browse files Browse the repository at this point in the history
  • Loading branch information
nkeim committed Jan 16, 2024
1 parent 17244de commit 88075db
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions trackpy/tests/test_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ def setUp(self):
for i in range(P)]
self.many_walks = conformity(pandas_concat(particles))

self.unlabeled_walks = self.many_walks.copy()
del self.unlabeled_walks['particle']

a = DataFrame({'x': np.arange(N), 'y': np.zeros(N),
'frame': np.arange(N), 'particle': np.zeros(N)})
b = DataFrame({'x': np.arange(1, N), 'y': Y + np.zeros(N - 1),
'frame': np.arange(1, N), 'particle': np.ones(N - 1)})
self.steppers = conformity(pandas_concat([a, b]))
self.unlabeled_steppers = self.steppers.copy()
del self.unlabeled_steppers['particle']

# Single-particle trajectory with no particle label
self.single_stepper = conformity(a)
del self.single_stepper['particle']

def test_no_drift(self):
N = 10
Expand Down Expand Up @@ -121,10 +126,15 @@ def test_subtract_constant_drift(self):
actual = tp.subtract_drift(add_drift(self.steppers, drift), drift)
assert_traj_equal(actual, self.steppers)

actual = tp.subtract_drift(add_drift(self.single_stepper, drift), drift)
assert_traj_equal(actual, self.single_stepper)

# Test that subtract_drift is OK without particle labels.
actual = tp.subtract_drift(add_drift(self.unlabeled_steppers, drift),
# In principle, Series.sub() may raise an error because
# the 'frame' index is duplicated.
# Don't check the result since we can't compare unlabeled trajectories!
actual = tp.subtract_drift(add_drift(self.unlabeled_walks, drift),
drift)
assert_traj_equal(actual, self.unlabeled_steppers)


class TestMSD(StrictTestCase):
Expand Down

0 comments on commit 88075db

Please sign in to comment.