@@ -185,3 +185,44 @@ def test_3d_distribution_function():
185185 with xr .open_dataset (EXAMPLE_3D_DIST_FN / "0000.sdf" ) as df :
186186 distribution_function = "dist_fn_x_px_py_Electron"
187187 assert df [distribution_function ].shape == (16 , 20 , 20 )
188+
189+
190+ def test_drop_variables ():
191+ with xr .open_dataset (
192+ EXAMPLE_FILES_DIR / "0000.sdf" , drop_variables = ["Electric_Field_Ex" ]
193+ ) as df :
194+ assert "Electric_Field_Ex" not in df
195+
196+
197+ def test_drop_variables_multiple ():
198+ with xr .open_dataset (
199+ EXAMPLE_FILES_DIR / "0000.sdf" ,
200+ drop_variables = ["Electric_Field_Ex" , "Electric_Field_Ey" ],
201+ ) as df :
202+ assert "Electric_Field_Ex" not in df
203+ assert "Electric_Field_Ey" not in df
204+
205+
206+ def test_drop_variables_original ():
207+ with xr .open_dataset (
208+ EXAMPLE_FILES_DIR / "0000.sdf" ,
209+ drop_variables = ["Electric_Field/Ex" , "Electric_Field/Ey" ],
210+ ) as df :
211+ assert "Electric_Field_Ex" not in df
212+ assert "Electric_Field_Ey" not in df
213+
214+
215+ def test_drop_variables_mixed ():
216+ with xr .open_dataset (
217+ EXAMPLE_FILES_DIR / "0000.sdf" ,
218+ drop_variables = ["Electric_Field/Ex" , "Electric_Field_Ey" ],
219+ ) as df :
220+ assert "Electric_Field_Ex" not in df
221+ assert "Electric_Field_Ey" not in df
222+
223+
224+ def test_erroring_drop_variables ():
225+ with pytest .raises (KeyError ):
226+ xr .open_dataset (
227+ EXAMPLE_FILES_DIR / "0000.sdf" , drop_variables = ["Electric_Field/E" ]
228+ )
0 commit comments