@@ -25,14 +25,18 @@ def tracks_df(n_nodes: int = 10) -> pd.DataFrame:
25
25
return pd .DataFrame (tracks_data , columns = ["track_id" , "t" , "z" , "y" , "x" ])
26
26
27
27
28
- def test_reader (tracks_df : pd .DataFrame , tmp_path : Path ):
29
- reader = napari_get_reader ("tracks.csv" )
28
+ @pytest .mark .parametrize ("file_ext" , ["csv" , "parquet" ])
29
+ def test_reader (tracks_df : pd .DataFrame , tmp_path : Path , file_ext : str ):
30
+ reader = napari_get_reader (f"tracks.{ file_ext } " )
30
31
assert reader is None
31
32
32
- path = tmp_path / "good_tracks.csv "
33
+ path = tmp_path / f "good_tracks.{ file_ext } "
33
34
tracks_df ["node_id" ] = np .arange (len (tracks_df )) + 1
34
35
tracks_df ["labels" ] = np .random .randint (2 , size = len (tracks_df ))
35
- tracks_df .to_csv (path , index = False )
36
+ if file_ext == "csv" :
37
+ tracks_df .to_csv (path , index = False )
38
+ else :
39
+ tracks_df .to_parquet (path )
36
40
37
41
reader = napari_get_reader (path )
38
42
assert callable (reader )
@@ -47,13 +51,17 @@ def test_reader(tracks_df: pd.DataFrame, tmp_path: Path):
47
51
assert np .allclose (data , tracks_df [["track_id" , "t" , "z" , "y" , "x" ]])
48
52
49
53
50
- def test_reader_2d (tracks_df : pd .DataFrame , tmp_path : Path ):
51
- reader = napari_get_reader ("tracks.csv" )
54
+ @pytest .mark .parametrize ("file_ext" , ["csv" , "parquet" ])
55
+ def test_reader_2d (tracks_df : pd .DataFrame , tmp_path : Path , file_ext : str ):
56
+ reader = napari_get_reader (f"tracks.{ file_ext } " )
52
57
assert reader is None
53
58
54
- path = tmp_path / "good_tracks.csv "
59
+ path = tmp_path / f "good_tracks.{ file_ext } "
55
60
tracks_df = tracks_df .drop (columns = ["z" ])
56
- tracks_df .to_csv (path , index = False )
61
+ if file_ext == "csv" :
62
+ tracks_df .to_csv (path , index = False )
63
+ else :
64
+ tracks_df .to_parquet (path )
57
65
58
66
reader = napari_get_reader (path )
59
67
assert callable (reader )
@@ -64,7 +72,8 @@ def test_reader_2d(tracks_df: pd.DataFrame, tmp_path: Path):
64
72
assert np .allclose (data , tracks_df [["track_id" , "t" , "y" , "x" ]])
65
73
66
74
67
- def test_reader_with_lineage (tmp_path : Path ):
75
+ @pytest .mark .parametrize ("file_ext" , ["csv" , "parquet" ])
76
+ def test_reader_with_lineage (tmp_path : Path , file_ext : str ):
68
77
tracks_df = pd .DataFrame (
69
78
{
70
79
"track_id" : [1 , 1 , 2 , 3 ],
@@ -76,8 +85,11 @@ def test_reader_with_lineage(tmp_path: Path):
76
85
}
77
86
)
78
87
79
- path = tmp_path / "tracks.csv"
80
- tracks_df .to_csv (path , index = False )
88
+ path = tmp_path / f"tracks.{ file_ext } "
89
+ if file_ext == "csv" :
90
+ tracks_df .to_csv (path , index = False )
91
+ else :
92
+ tracks_df .to_parquet (path )
81
93
82
94
reader = napari_get_reader (path )
83
95
assert callable (reader )
@@ -95,26 +107,37 @@ def test_non_existing_track():
95
107
assert reader is None
96
108
97
109
98
- def test_wrong_columns_track (tracks_df : pd .DataFrame , tmp_path : Path ):
99
- reader = napari_get_reader ("tracks.csv" )
110
+ @pytest .mark .parametrize ("file_ext" , ["csv" , "parquet" ])
111
+ def test_wrong_columns_track (tracks_df : pd .DataFrame , tmp_path : Path , file_ext : str ):
112
+ reader = napari_get_reader (f"tracks.{ file_ext } " )
100
113
assert reader is None
101
114
102
- path = tmp_path / "bad_tracks.csv "
115
+ path = tmp_path / f "bad_tracks.{ file_ext } "
103
116
tracks_df = tracks_df .rename (columns = {"track_id" : "id" })
104
- tracks_df .to_csv (path , index = False )
117
+ if file_ext == "csv" :
118
+ tracks_df .to_csv (path , index = False )
119
+ else :
120
+ tracks_df .to_parquet (path )
121
+
105
122
reader = napari_get_reader (path )
106
123
assert reader is None
107
124
108
125
126
+ @pytest .mark .parametrize ("file_ext" , ["csv" , "parquet" ])
109
127
def test_napari_viewer_open_tracks (
110
128
make_napari_viewer : Callable [[], ViewerModel ],
111
129
tracks_df : pd .DataFrame ,
112
130
tmp_path : Path ,
131
+ file_ext : str ,
113
132
) -> None :
114
133
115
134
_initialize_plugins ()
116
135
117
- tracks_df .to_csv (tmp_path / "tracks.csv" , index = False )
136
+ path = tmp_path / f"tracks.{ file_ext } "
137
+ if file_ext == "csv" :
138
+ tracks_df .to_csv (path , index = False )
139
+ else :
140
+ tracks_df .to_parquet (path )
118
141
119
142
viewer = make_napari_viewer ()
120
- viewer .open (tmp_path / "tracks.csv" , plugin = "ultrack" )
143
+ viewer .open (path , plugin = "ultrack" )
0 commit comments