Skip to content

Commit 15b0bc2

Browse files
committed
Updated the remaining test cases
1 parent 44222ab commit 15b0bc2

5 files changed

Lines changed: 126 additions & 130 deletions

File tree

mapmanagercore/lazy_geo_pandas/lazy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,16 @@ def _getFiltered(self, keys):
469469
# Some computed keys might be missing when the root frame is empty
470470
# Temporary add empty series as placeholders for those computed columns
471471
df = self._df
472+
472473
columns = self.columns
473474
if not isinstance(keys, list):
474475
if keys in df.columns or not keys in columns:
475476
return self._df[keys]
476477
return pd.Series()
477478

479+
if df.empty:
480+
return pd.DataFrame({key: pd.Series() for key in keys})
481+
478482
keyGroups = [], []
479483
for key in keys:
480484
keyGroups[key in columns and not key in df.columns].append(key)

mapmanagercore/lazy_geo_pd_images/loader/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def metadata(self, t: int) -> Metadata:
4545

4646
def timePoints(self) -> Iterator[int]:
4747
("implemented by subclass")
48+
return []
4849

4950
def _images(self, t: int) -> np.ndarray:
5051
("implemented by subclass", t)
52+
return np.array([])
5153

5254
def loadSlice(self, time: int, channel: int, slice: int) -> np.ndarray:
5355
"""
@@ -90,6 +92,9 @@ def channels(self, t: int = None) -> int:
9092
"""
9193

9294
if t is None:
95+
if len(self.timePoints()) == 0:
96+
return 0
97+
9398
return min(self.shape(t)[0] for t in self.timePoints())
9499

95100
return self.shape(t)[0]

tests/test_base_mutation.py

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
import unittest
22
from mapmanagercore.annotations.mutation import AnnotationsBaseMut
3-
from mapmanagercore.loader.base import Loader
3+
from mapmanagercore.lazy_geo_pd_images.loader.base import ImageLoader
4+
from mapmanagercore.schemas.segment import Segment
5+
from mapmanagercore.schemas.spine import Spine
6+
47

58
class TestAnnotationsBaseMut(unittest.TestCase):
69

710
def new(self):
8-
return AnnotationsBaseMut(Loader())
11+
return AnnotationsBaseMut(ImageLoader())
912

1013
def test_undo_redo_simple_spine(self):
1114
annotations = self.new()
12-
annotations.updateSpine(("spine_id", 0), {"z": 0})
13-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 0)
15+
annotations.updateSpine(("spine_id", 0), Spine(z=0))
16+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 0)
1417

1518
# Undo the update
1619
annotations.undo()
1720
self.assertNotIn(("spine_id", 0), annotations._points.index)
1821

1922
# Redo the update
2023
annotations.redo()
21-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 0)
24+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 0)
2225

2326
# Redo again (should have no effect)
2427
annotations.redo()
25-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 0)
28+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 0)
2629

27-
annotations.updateSpine(("spine_id", 0), {"z": 1})
28-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 1)
30+
annotations.updateSpine(("spine_id", 0), Spine(z=1))
31+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 1)
2932
annotations.undo()
30-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 0)
33+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 0)
3134
annotations.redo()
32-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 1)
35+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 1)
3336
annotations.undo()
34-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 0)
37+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 0)
3538

3639
# Undo twice (should have no effect)
3740
annotations.undo()
@@ -42,48 +45,48 @@ def test_undo_redo_simple_spine(self):
4245
def test_undo_redo_replace(self):
4346
annotations = self.new()
4447
# Test replaceLog
45-
annotations.updateSpine(("spine_id", 0), {"z": 2})
48+
annotations.updateSpine(("spine_id", 0), Spine(z=2))
4649
self.assertEqual(len(annotations._log.operations), 1)
47-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 2)
50+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 2)
4851

49-
annotations.updateSpine(("spine_id", 0), {"z": 3})
52+
annotations.updateSpine(("spine_id", 0), Spine(z=3))
5053
self.assertEqual(len(annotations._log.operations), 2)
51-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 3)
54+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 3)
5255

53-
annotations.updateSpine(("spine_id", 0), {"z": 4}, replaceLog=True)
56+
annotations.updateSpine(("spine_id", 0), Spine(z=4), replaceLog=True)
5457
self.assertEqual(len(annotations._log.operations), 2)
55-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 4)
58+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 4)
5659

5760
annotations.undo()
58-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 2)
61+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 2)
5962

6063
annotations.undo()
6164
self.assertNotIn(("spine_id", 0), annotations._points.index)
6265

6366
annotations.redo()
64-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 2)
67+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 2)
6568

6669
annotations.redo()
67-
self.assertEqual(annotations._points.loc[("spine_id", 0), "z"], 4)
70+
self.assertEqual(annotations.points[("spine_id", 0), "z"], 4)
6871

6972
def test_undo_redo_simple_segment(self):
7073
annotations = self.new()
71-
annotations.updateSegment(("segment_id", 0), {"radius": 1})
74+
annotations.updateSegment(("segment_id", 0), Segment(radius=1))
7275
self.assertEqual(
73-
annotations._lineSegments.loc[("segment_id", 0), "radius"], 1)
76+
annotations.segments[("segment_id", 0), "radius"], 1)
7477

7578
# Undo the update
7679
annotations.undo()
77-
self.assertNotIn(("segment_id", 0), annotations._lineSegments.index)
80+
self.assertNotIn(("segment_id", 0), annotations.segments.index)
7881

7982
# Redo the update
8083
annotations.redo()
8184
self.assertEqual(
82-
annotations._lineSegments.loc[("segment_id", 0), "radius"], 1)
85+
annotations.segments[("segment_id", 0), "radius"], 1)
8386

8487
def test_delete_spine(self):
8588
annotations = self.new()
86-
annotations.updateSpine(("spine_id", 0), {"z": 0})
89+
annotations.updateSpine(("spine_id", 0), Spine(z=0))
8790
self.assertIn(("spine_id", 0), annotations._points.index)
8891

8992
# Delete the spine
@@ -100,57 +103,58 @@ def test_delete_spine(self):
100103

101104
def test_delete_segment(self):
102105
annotations = self.new()
103-
annotations.updateSegment(("segment_id", 0), {"radius": 1})
104-
self.assertIn(("segment_id", 0), annotations._lineSegments.index)
106+
annotations.updateSegment(("segment_id", 0), Segment(radius=1))
107+
self.assertIn(("segment_id", 0), annotations.segments.index)
105108

106109
# Delete the segment
107110
annotations.deleteSegment(("segment_id", 0))
108-
self.assertNotIn(("segment_id", 0), annotations._lineSegments.index)
111+
self.assertNotIn(("segment_id", 0), annotations.segments.index)
109112

110113
# Undo the deletion
111114
annotations.undo()
112-
self.assertIn(("segment_id", 0), annotations._lineSegments.index)
115+
self.assertIn(("segment_id", 0), annotations.segments.index)
113116

114117
# Redo the deletion
115118
annotations.redo()
116-
self.assertNotIn(("segment_id", 0), annotations._lineSegments.index)
117-
119+
self.assertNotIn(("segment_id", 0), annotations.segments.index)
120+
118121
def test_multi_segment(self):
119122
annotations = self.new()
120-
annotations.updateSegment(("segment_id", 0), {"radius": 1})
121-
annotations.updateSegment(("segment_id2", 0), {"radius": 2})
122-
self.assertIn(("segment_id", 0), annotations._lineSegments.index)
123-
self.assertIn(("segment_id2", 0), annotations._lineSegments.index)
124-
125-
self.assertEqual(annotations._lineSegments.loc[("segment_id", 0), "radius"], 1)
126-
self.assertEqual(annotations._lineSegments.loc[("segment_id2", 0), "radius"], 2)
127-
128-
annotations.updateSegment([("segment_id", 0), ("segment_id2", 0)], {"radius": 3})
129-
self.assertEqual(annotations._lineSegments.loc[("segment_id", 0), "radius"], 3)
130-
self.assertEqual(annotations._lineSegments.loc[("segment_id2", 0), "radius"], 3)
131-
123+
annotations.updateSegment(("segment_id", 0), Segment(radius=1))
124+
annotations.updateSegment(("segment_id2", 0), Segment(radius=2))
125+
self.assertIn(("segment_id", 0), annotations.segments.index)
126+
self.assertIn(("segment_id2", 0), annotations.segments.index)
127+
128+
self.assertEqual(annotations.segments[("segment_id", 0), "radius"], 1)
129+
self.assertEqual(annotations.segments[("segment_id2", 0), "radius"], 2)
130+
131+
annotations.updateSegment(
132+
[("segment_id", 0), ("segment_id2", 0)], Segment(radius=3))
133+
self.assertEqual(annotations.segments[("segment_id", 0), "radius"], 3)
134+
self.assertEqual(annotations.segments[("segment_id2", 0), "radius"], 3)
135+
132136
annotations.undo()
133-
self.assertEqual(annotations._lineSegments.loc[("segment_id", 0), "radius"], 1)
134-
self.assertEqual(annotations._lineSegments.loc[("segment_id2", 0), "radius"], 2)
135-
137+
self.assertEqual(annotations.segments[("segment_id", 0), "radius"], 1)
138+
self.assertEqual(annotations.segments[("segment_id2", 0), "radius"], 2)
139+
136140
annotations.redo()
137-
self.assertEqual(annotations._lineSegments.loc[("segment_id", 0), "radius"], 3)
138-
self.assertEqual(annotations._lineSegments.loc[("segment_id2", 0), "radius"], 3)
139-
141+
self.assertEqual(annotations.segments[("segment_id", 0), "radius"], 3)
142+
self.assertEqual(annotations.segments[("segment_id2", 0), "radius"], 3)
143+
140144
# Delete the segment
141145
annotations.deleteSegment([("segment_id", 0), ("segment_id2", 0)])
142-
self.assertNotIn(("segment_id", 0), annotations._lineSegments.index)
143-
self.assertNotIn(("segment_id2", 0), annotations._lineSegments.index)
146+
self.assertNotIn(("segment_id", 0), annotations.segments.index)
147+
self.assertNotIn(("segment_id2", 0), annotations.segments.index)
144148

145149
# Undo the deletion
146150
annotations.undo()
147-
self.assertIn(("segment_id", 0), annotations._lineSegments.index)
148-
self.assertIn(("segment_id2", 0), annotations._lineSegments.index)
151+
self.assertIn(("segment_id", 0), annotations.segments.index)
152+
self.assertIn(("segment_id2", 0), annotations.segments.index)
149153

150154
# Redo the deletion
151155
annotations.redo()
152-
self.assertNotIn(("segment_id", 0), annotations._lineSegments.index)
153-
self.assertNotIn(("segment_id2", 0), annotations._lineSegments.index)
156+
self.assertNotIn(("segment_id", 0), annotations.segments.index)
157+
self.assertNotIn(("segment_id2", 0), annotations.segments.index)
154158

155159

156160
if __name__ == '__main__':

0 commit comments

Comments
 (0)