diff --git a/nonos/api/analysis.py b/nonos/api/analysis.py index d8cc67e8..cb225930 100644 --- a/nonos/api/analysis.py +++ b/nonos/api/analysis.py @@ -1652,3 +1652,12 @@ def items(self) -> ItemsView[str, "GasField"]: items of the dict """ return self.dict.items() + + @property + def nfields(self) -> int: + """ + Returns + ======= + The number of fields in the GasDataSet + """ + return len(self.dict) diff --git a/tests/test_load_data.py b/tests/test_load_data.py index 51868089..df3d19d7 100644 --- a/tests/test_load_data.py +++ b/tests/test_load_data.py @@ -20,13 +20,13 @@ def test_roundtrip_simple(test_data_dir, tmp_path): os.chdir(tmp_path / "mydir") ds = GasDataSet(500) - assert len(list(ds.keys())) == 7 + assert ds.nfields == 7 gf = ds["RHO"].azimuthal_average() gf.save() dsnpy = GasDataSet.from_npy(500, operation="azimuthal_average") - assert len(list(dsnpy.keys())) == 1 + assert dsnpy.nfields == 1 def test_roundtrip_other_dir(test_data_dir, tmp_path): @@ -34,7 +34,7 @@ def test_roundtrip_other_dir(test_data_dir, tmp_path): gf = GasDataSet(500)["RHO"].azimuthal_average() gf.save(tmp_path) dsnpy = GasDataSet.from_npy(500, operation="azimuthal_average", directory=tmp_path) - assert len(list(dsnpy.keys())) == 1 + assert dsnpy.nfields == 1 def test_api_vtk_by_name(test_data_dir): @@ -64,7 +64,7 @@ def test_api_fluid_fargo3d(test_data_dir): on = 5 ds = GasDataSet(on, fluid="dust2") - assert len(list(ds.keys())) == 1 + assert ds.nfields == 1 with pytest.raises( FileNotFoundError,