Repository: DHI/mikeio
Pull request #302 (2022-03-29 14:16:49)

Use to_numpy() or values instead of data property


Patch:
diff --git a/mikeio/dataset.py b/mikeio/dataset.py
index 65d10c88..c09dc8e9 100644
--- a/mikeio/dataset.py
+++ b/mikeio/dataset.py
@@ -162,14 +162,11 @@ class Dataset(DataUtilsMixin, TimeSeries, collections.abc.MutableMapping):
         zn=None,
         dims=None,
     ):
-        if self._is_DataArrays(data):
-            validate = True
-        else:
+        if not self._is_DataArrays(data):
             data = self._create_dataarrays(
                 data=data, time=time, items=items, geometry=geometry, zn=zn, dims=dims
             )
-            validate = False
-        return self._init_from_DataArrays(data, validate=validate)
+        return self._init_from_DataArrays(data, validate=True)
 
     @staticmethod
     def _is_DataArrays(data):
@@ -931,8 +928,8 @@ class Dataset(DataUtilsMixin, TimeSeries, collections.abc.MutableMapping):
         idx2 = np.where(~df12["idx2"].isna())
         for j in range(ds.n_items):
             # if there is an overlap "other" data will be used!
-            newdata[j][idx1, :] = ds.data[j]
-            newdata[j][idx2, :] = other.data[j]
+            newdata[j][idx1, :] = ds[j].to_numpy()
+            newdata[j][idx2, :] = other[j].to_numpy()
 
         return Dataset(newdata, newtime, ds.items)
 
diff --git a/mikeio/dfs.py b/mikeio/dfs.py
index f274d02a..63a55818 100644
--- a/mikeio/dfs.py
+++ b/mikeio/dfs.py
@@ -294,7 +294,7 @@ class _Dfs123(TimeSeries):
             self._start_time = data.time[0]
             if dt is None and len(data.time) > 1:
                 self._dt = (data.time[1] - data.time[0]).total_seconds()
-            self._data = data.data
+            self._data = data.to_numpy()
         else:
             self._data = data
 
diff --git a/mikeio/dfs0.py b/mikeio/dfs0.py
index 9d301c77..ea30013f 100644
--- a/mikeio/dfs0.py
+++ b/mikeio/dfs0.py
@@ -69,7 +69,7 @@ def _write_dfs0(filename, dataset: Dataset, title="", dtype=DfsSimpleType.Float)
 
     t_seconds = (dataset.time - dataset.time[0]).total_seconds().values
 
-    data = np.array(dataset.data, order="F").astype(np.float64).T
+    data = np.array(dataset.to_numpy(), order="F").astype(np.float64).T
     data[np.isnan(data)] = delete_value
     data_to_write = np.concatenate([t_seconds.reshape(-1, 1), data], axis=1)
     rc = dfs.WriteDfs0DataDouble(data_to_write)
@@ -351,7 +351,7 @@ class Dfs0(TimeSeries):
                 self._dt = (data.time[1] - data.time[0]).total_seconds()
             else:
                 datetimes = data.time
-            data = data.data
+            data = data.to_numpy()
         elif datetimes is not None:
             datetimes = pd.DatetimeIndex(datetimes, freq="infer")
 
diff --git a/mikeio/dfs3.py b/mikeio/dfs3.py
index 69796084..f648f2d3 100644
--- a/mikeio/dfs3.py
+++ b/mikeio/dfs3.py
@@ -27,7 +27,7 @@ class Dfs3(_Dfs123):
         for item_number in range(self.n_items):
             b = np.nan * np.ones(self.shape[2:])
             for ts in range(self.n_timesteps):
-                d = data.data[item_number][ts, ...]
+                d = data[item_number].values[ts, ...]
                 for layer in range(d.shape[0]):  # going from surface to bottom
                     y = d[layer, ...]
                     b[~np.isnan(y)] = y[~np.isnan(y)]
diff --git a/mikeio/dfsu.py b/mikeio/dfsu.py
index 4f0f7a7b..8687e9b2 100644
--- a/mikeio/dfsu.py
+++ b/mikeio/dfsu.py
@@ -990,7 +990,9 @@ class _Dfsu(_UnstructuredFile, EquidistantTimeSeries):
                 dt = (data.time[1] - data.time[0]).total_seconds()
             if data.geometry.is_layered:
                 zn_dynamic = data[0]._zn
-            data = data.data
+
+            # data needs to be a list so we can fit zn later
+            data = [x.to_numpy() for x in data]
 
         n_items = len(data)
         n_time_steps = 0
@@ -1246,8 +1248,8 @@ class Dfsu2DH(_Dfsu):
         elif isinstance(track, Dataset):
             times = track.time
             coords = np.zeros(shape=(len(times), 2))
-            coords[:, 0] = track.data[0].copy()
-            coords[:, 1] = track.data[1].copy()
+            coords[:, 0] = track[0].to_numpy().copy()
+            coords[:, 1] = track[1].to_numpy().copy()
         else:
             assert isinstance(track, pd.DataFrame)
             times = track.index
diff --git a/mikeio/dfsu_layered.py b/mikeio/dfsu_layered.py
index 05961e76..5ff62dfe 100644
--- a/mikeio/dfsu_layered.py
+++ b/mikeio/dfsu_layered.py
@@ -456,7 +456,7 @@ class Dfsu3D(DfsuLayered):
         node_ids_surf, _ = self.geometry._get_nodes_and_table_for_elements(
             top_el, node_layers="top"
         )
-        zn_surf = ds.data[0][:, node_ids_surf]  # surface
+        zn_surf = ds[0].values[:, node_ids_surf]  # surface
         surf2d = interp2d(zn_surf, node_ids, weights)
 
         # create output


Test patch:
diff --git a/tests/test_aggregator.py b/tests/test_aggregator.py
index 5048235d..1465ba5e 100644
--- a/tests/test_aggregator.py
+++ b/tests/test_aggregator.py
@@ -9,14 +9,14 @@ def test_dfs2_to_dfs1_y_direction(tmpdir):
 
     ds2 = mikeio.read(dfs2file)
 
-    assert ds2.data[0].shape == (25, 10, 20)  # t, y, x
+    assert ds2[0].values.shape == (25, 10, 20)  # t, y, x
 
     dfs1file1 = os.path.join(tmpdir.dirname, "eq_ax_y.dfs1")
     dfs2todfs1(dfs2file, dfs1file1)  # default aggregation is over y axis
 
     ds1 = mikeio.read(dfs1file1)
 
-    assert ds1.data[0].shape == (25, 20)
+    assert ds1[0].values.shape == (25, 20)
 
 
 def test_dfs2_to_dfs1_x_direction(tmpdir):
@@ -25,14 +25,14 @@ def test_dfs2_to_dfs1_x_direction(tmpdir):
 
     ds2 = mikeio.read(dfs2file)
 
-    assert ds2.data[0].shape == (25, 10, 20)
+    assert ds2[0].values.shape == (25, 10, 20)
 
     dfs1file1 = os.path.join(tmpdir.dirname, "eq_ax_x.dfs1")
     dfs2todfs1(dfs2file, dfs1file1, axis=2)
 
     ds1 = mikeio.read(dfs1file1)
 
-    assert ds1.data[0].shape == (25, 10)
+    assert ds1[0].values.shape == (25, 10)
 
 
 def test_dfsu_to_dfs0(tmpdir):
@@ -41,11 +41,11 @@ def test_dfsu_to_dfs0(tmpdir):
 
     ds_in = mikeio.read(dfsufile)
 
-    assert ds_in.data[0].shape == (9, 884)
+    assert ds_in[0].values.shape == (9, 884)
 
     dfs0file1 = os.path.join(tmpdir.dirname, "HD2D_mean.dfs0")
     dfstodfs0(dfsufile, dfs0file1)
 
     ds0 = mikeio.read(dfs0file1)
 
-    assert ds0.data[0].shape == (9,)
+    assert ds0[0].values.shape == (9,)
diff --git a/tests/test_dataset.py b/tests/test_dataset.py
index 3de25fd5..017182a4 100644
--- a/tests/test_dataset.py
+++ b/tests/test_dataset.py
@@ -221,7 +221,7 @@ def test_select_subset_isel():
     selds = ds.isel(10, axis=1)
 
     assert len(selds.items) == 2
-    assert len(selds.data) == 2
+    assert len(selds.to_numpy()) == 2
     assert selds["Foo"].shape == (100, 30)
     assert selds["Foo"].to_numpy()[0, 0] == 2.0
     assert selds["Bar"].to_numpy()[0, 0] == 3.0
@@ -412,7 +412,7 @@ def test_select_subset_isel_multiple_idxs():
     selds = ds.isel([10, 15], axis=1)
 
     assert len(selds.items) == 2
-    assert len(selds.data) == 2
+    assert len(selds.to_numpy()) == 2
     assert selds["Foo"].shape == (100, 2, 30)
 
 
@@ -440,7 +440,7 @@ def test_create_undefined():
     ds = mikeio.Dataset(data)
 
     assert len(ds.items) == 2
-    assert len(ds.data) == 2
+    assert len(ds.to_numpy()) == 2
     assert ds[0].name == "Item 1"
     assert ds[0].type == EUMType.Undefined
 
@@ -457,7 +457,7 @@ def test_create_named_undefined():
     ds = mikeio.Dataset(data=data, time=time, items=["Foo", "Bar"])
 
     assert len(ds.items) == 2
-    assert len(ds.data) == 2
+    assert len(ds.to_numpy()) == 2
     assert ds[1].name == "Bar"
     assert ds[1].type == EUMType.Undefined
 
@@ -519,7 +519,7 @@ def test_get_data():
     items = [ItemInfo("Foo")]
     ds = mikeio.Dataset(data, time, items)
 
-    assert ds.data[0].shape == (100, 100, 30)
+    assert ds.shape == (100, 100, 30)
 
 
 def test_interp_time():
@@ -550,7 +550,7 @@ def test_interp_time_to_other_dataset():
     time = pd.date_range("2000-1-1", freq="D", periods=nt)
     items = [ItemInfo("Foo")]
     ds1 = mikeio.Dataset(data, time, items)
-    assert ds1.data[0].shape == (nt, 10, 3)
+    assert ds1.shape == (nt, 10, 3)
 
     ## mikeio.Dataset 2
     nt = 12
@@ -567,7 +567,7 @@ def test_interp_time_to_other_dataset():
     assert dsi.time[0] == ds2.time[0]
     assert dsi.time[-1] == ds2.time[-1]
     assert len(dsi.time) == len(ds2.time)
-    assert dsi.data[0].shape[0] == ds2.data[0].shape[0]
+    assert dsi[0].shape[0] == ds2[0].shape[0]
 
     # Accept dataset as argument
     dsi2 = ds1.interp_time(ds2)
@@ -582,7 +582,7 @@ def test_extrapolate():
     time = pd.date_range("2000-1-1", freq="D", periods=nt)
     items = [ItemInfo("Foo")]
     ds1 = mikeio.Dataset(data, time, items)
-    assert ds1.data[0].shape == (nt, 10, 3)
+    assert ds1.shape == (nt, 10, 3)
 
     ## mikeio.Dataset 2 partly overlapping with mikeio.Dataset 1
     nt = 3
@@ -599,9 +599,9 @@ def test_extrapolate():
     assert dsi.time[0] == ds2.time[0]
     assert dsi.time[-1] == ds2.time[-1]
     assert len(dsi.time) == len(ds2.time)
-    assert dsi.data[0][0] == pytest.approx(0.0)
-    assert dsi.data[0][1] == pytest.approx(1.0)  # filled
-    assert dsi.data[0][2] == pytest.approx(1.0)  # filled
+    assert dsi[0].values[0] == pytest.approx(0.0)
+    assert dsi[0].values[1] == pytest.approx(1.0)  # filled
+    assert dsi[0].values[2] == pytest.approx(1.0)  # filled
 
 
 def test_extrapolate_not_allowed():
@@ -611,7 +611,7 @@ def test_extrapolate_not_allowed():
     time = pd.date_range("2000-1-1", freq="D", periods=nt)
     items = [ItemInfo("Foo")]
     ds1 = mikeio.Dataset(data, time, items)
-    assert ds1.data[0].shape == (nt, 10, 3)
+    assert ds1.shape == (nt, 10, 3)
 
     ## mikeio.Dataset 2 partly overlapping with mikeio.Dataset 1
     nt = 3
@@ -829,7 +829,7 @@ def test_copy():
     ds = mikeio.Dataset(data, time, items)
 
     assert len(ds.items) == 2
-    assert len(ds.data) == 2
+    assert len(ds.to_numpy()) == 2
     assert ds[0].name == "Foo"
 
     ds2 = ds.copy()
@@ -855,7 +855,7 @@ def test_dropna():
     ds = mikeio.Dataset(data, time, items)
 
     assert len(ds.items) == 2
-    assert len(ds.data) == 2
+    assert len(ds.to_numpy()) == 2
 
     ds2 = ds.dropna()
 
diff --git a/tests/test_dfs0.py b/tests/test_dfs0.py
index 57440aab..e3ac41c9 100644
--- a/tests/test_dfs0.py
+++ b/tests/test_dfs0.py
@@ -283,14 +283,14 @@ def test_read_dfs0_delete_value_conversion():
     dfs = Dfs0(dfs0file)
     ds = dfs.read()
 
-    assert np.isnan(ds.data[3][1])
+    assert np.isnan(ds[3].values[1])
 
     dfs0file = r"tests/testdata/random.dfs0"
 
     dfs = Dfs0(dfs0file)
     ds = dfs.read()
 
-    assert np.isnan(ds.data[0][2])
+    assert np.isnan(ds[0].values[2])
 
 
 def test_read_dfs0_small_value_not_delete_value(tmpdir):
@@ -311,7 +311,7 @@ def test_read_dfs0_small_value_not_delete_value(tmpdir):
     dfs = Dfs0(filename)
     ds = dfs.read()
 
-    assert not np.isnan(ds.data[0]).any()
+    assert not np.isnan(ds[0].to_numpy()).any()
 
 
 def test_write_from_data_frame(tmpdir):
@@ -425,7 +425,7 @@ def test_read_dfs0_single_item():
     dfs = Dfs0(dfs0file)
     ds = dfs.read([1])
 
-    assert len(ds.data) == 1
+    assert len(ds.to_numpy()) == 1
 
 
 def test_read_dfs0_single_item_named_access():
@@ -434,9 +434,8 @@ def test_read_dfs0_single_item_named_access():
 
     dfs = Dfs0(dfs0file)
     res = dfs.read(items=[1])
-    data = res.data
 
-    assert len(data) == 1
+    assert len(res.to_numpy()) == 1
 
 
 def test_read_dfs0_temporal_subset():
@@ -466,7 +465,7 @@ def test_read_dfs0_single_item_read_by_name():
 
     dfs = Dfs0(dfs0file)
     res = dfs.read(["NotFun", "VarFun01"])  # reversed order compare to original file
-    data = res.data
+    data = res.to_numpy()
 
     assert len(data) == 2
     assert res.items[0].name == "NotFun"
@@ -491,7 +490,7 @@ def test_read_dfs0_to_matrix():
     dfs = Dfs0(dfs0file)
     ds = dfs.read()
 
-    assert len(ds.data) == 2
+    assert len(ds.to_numpy()) == 2
 
 
 def test_write_data_with_missing_values(tmpdir):
@@ -502,21 +501,21 @@ def test_write_data_with_missing_values(tmpdir):
     ds = dfs.read()
 
     # Do something with the data
-    ds.data[0] = np.zeros_like(ds.data[0])
-    ds.data[1] = np.ones_like(ds.data[0])
+    ds[0].values = np.zeros_like(ds[0].values)
+    ds[1].values = np.ones_like(ds[0].values)
 
     # Add some NaNs
-    ds.data[1][0:10] = np.nan
+    ds[1].values[0:10] = np.nan
 
     # Overwrite the file
     dfs.write(tmpfile, ds)
 
     # Write operation does not modify the data
-    assert np.isnan(ds.data[1][1])
+    assert np.isnan(ds[1].values[1])
 
     moddfs = Dfs0(tmpfile)
     modified = moddfs.read()
-    assert np.isnan(modified.data[1][5])
+    assert np.isnan(modified[1].values[5])
 
 
 def test_read_relative_time_axis():
diff --git a/tests/test_dfs1.py b/tests/test_dfs1.py
index 69fcec78..5a98a458 100644
--- a/tests/test_dfs1.py
+++ b/tests/test_dfs1.py
@@ -86,7 +86,7 @@ def test_read():
     dfs = Dfs1(filename)
 
     ds = dfs.read(items=[0])
-    data = ds.data[0]
+    data = ds[0].to_numpy()
     assert data.shape == (100, 3)  # time, x
 
 
@@ -96,7 +96,7 @@ def test_read_item_names():
     dfs = Dfs1(filename)
 
     ds = dfs.read(items=["testing water level"])
-    data = ds.data[0]
+    data = ds[0].to_numpy()
     assert data.shape == (100, 3)  # time, x
 
 
@@ -106,7 +106,7 @@ def test_read_time_steps():
     dfs = Dfs1(filename)
 
     ds = dfs.read(time=[3, 5])
-    data = ds.data[0]
+    data = ds[0].to_numpy()
     assert data.shape == (2, 3)  # time, x
 
 
@@ -117,7 +117,7 @@ def test_write_some_time_steps_new_file(tmpdir):
     dfs = Dfs1(filename)
 
     ds = dfs.read(time=[0, 1, 2, 3, 4, 5])
-    data = ds.data[0]
+    data = ds[0].to_numpy()
     assert data.shape == (6, 3)  # time, x
 
     dfs.write(outfilename, ds)
@@ -144,10 +144,9 @@ def test_read_names_access():
     dfs = Dfs1(filename)
 
     res = dfs.read(items=[0])
-    data = res.data
-    item = data[0]
+    item_data = res[0].to_numpy()
     time = res.time
-    assert item.shape == (100, 3)  # time, x
+    assert item_data.shape == (100, 3)  # time, x
     assert len(time) == 100
     assert res.items[0].name == "testing water level"
     assert res.items[0].type == EUMType.Water_Level
diff --git a/tests/test_dfs2.py b/tests/test_dfs2.py
index 956fceac..5e1a3895 100644
--- a/tests/test_dfs2.py
+++ b/tests/test_dfs2.py
@@ -77,22 +77,23 @@ def test_write_inconsistent_shape(tmpdir):
 
     filename = os.path.join(tmpdir.dirname, "simple.dfs2")
 
-    data = []
-
     nt = 100
     nx = 20
     ny = 5
     d1 = np.random.random([nt, ny, nx])
     d2 = np.random.random([nt, ny, nx + 1])
 
-    data = Dataset(
-        data=[d1, d2], time=pd.date_range(start="2000", periods=nt, freq="H")
-    )
+    with pytest.raises(ValueError):
+        Dataset(data=[d1, d2], time=pd.date_range(start="2000", periods=nt, freq="H"))
 
-    dfs = Dfs2()
+    # trick Dataset to accept DataArrays of different shapes
+    d2 = np.random.random([nt, ny, nx])
+    ds = Dataset(data=[d1, d2], time=pd.date_range(start="2000", periods=nt, freq="H"))
+    ds[1]._values = np.random.random([nt, ny, nx + 1])
 
-    with pytest.raises(DataDimensionMismatch):
-        dfs.write(filename=filename, data=data)
+    dfs = Dfs2()
+    with pytest.raises(ValueError):
+        dfs.write(filename=filename, data=ds)
 
 
 def test_write_single_item(tmpdir):
@@ -363,7 +364,7 @@ def test_write_some_time_step(tmpdir):
 
     ds = dfs.read(time=[1, 2])
 
-    assert ds.data[0].shape[0] == 2
+    assert ds[0].to_numpy().shape[0] == 2
     assert len(ds.time) == 2
 
     assert dfs.timestep == 86400.0
diff --git a/tests/test_dfs3.py b/tests/test_dfs3.py
index ff5ab9b9..582b25d8 100644
--- a/tests/test_dfs3.py
+++ b/tests/test_dfs3.py
@@ -45,9 +45,8 @@ def test_read_write(tmpdir):
     dfs = Dfs3("tests/testdata/Grid1.dfs3")
     ds = dfs.read()
     outfilename = os.path.join(tmpdir.dirname, "rw.dfs3")
-    start_time = datetime(2012, 1, 1)
     items = ds.items
-    data = ds.data
+    data = ds.to_numpy()
     title = "test dfs3"
     dfs = Dfs3()
     dfs.write(
diff --git a/tests/test_dfsu.py b/tests/test_dfsu.py
index a729690f..007ab652 100644
--- a/tests/test_dfsu.py
+++ b/tests/test_dfsu.py
@@ -109,7 +109,7 @@ def test_read_returns_array_time_dimension_first():
 
     ds = dfs.read(items=[3])
 
-    assert ds.data[0].shape == (9, 884)
+    assert ds.shape == (9, 884)
 
 
 def test_read_selected_item_returns_correct_items():
@@ -142,7 +142,7 @@ def test_read_all_time_steps():
     ds = dfs.read(items=[0, 3])
 
     assert len(ds.time) == 9
-    assert ds.data[0].shape[0] == 9
+    assert ds[0].to_numpy().shape[0] == 9
 
 
 def test_read_item_range():
@@ -167,7 +167,7 @@ def test_read_all_time_steps_without_progressbar():
     ds = dfs.read(items=[0, 3])
 
     assert len(ds.time) == 9
-    assert ds.data[0].shape[0] == 9
+    assert ds[0].to_numpy().shape[0] == 9
 
 
 def test_read_single_time_step():
@@ -190,7 +190,7 @@ def test_read_single_time_step_scalar():
     ds = dfs.read(items=[0, 3], time=1)
 
     assert len(ds.time) == 1
-    assert ds.data[0].shape[0] == dfs.n_elements
+    assert ds[0].to_numpy().shape[0] == dfs.n_elements
 
 
 def test_read_single_time_step_outside_bounds_fails():
@@ -363,13 +363,13 @@ def test_read_and_select_single_element():
 
     ds = dfs.read()
 
-    assert ds.data[0].shape == (9, 884)
+    assert ds[0].to_numpy().shape == (9, 884)
 
     idx = dfs.find_nearest_elements(606200, 6905480)
 
     selds = ds.isel(idx=idx, axis=1)
 
-    assert selds.data[0].shape == (9,)
+    assert selds[0].to_numpy().shape == (9,)
 
 
 def test_is_2d():
@@ -583,7 +583,7 @@ def test_write_from_dfsu_default_items_numbered(tmpdir):
 
     ds = dfs.read(items=[0, 1])
 
-    dfs.write(outfilename, ds.data)
+    dfs.write(outfilename, ds.to_numpy())  # TODO: use ds.to_dfs() instead
 
     assert os.path.exists(outfilename)
 
@@ -801,7 +801,7 @@ def test_get_node_centered_data():
     dfs = Dfsu(filename)
     ds = dfs.read(items="Surface elevation")
     time_step = 0
-    wl_cc = ds.data[0][time_step, :]
+    wl_cc = ds[0].values[time_step, :]
     wl_nodes = dfs.get_node_centered_data(wl_cc)
 
     eid = 31
@@ -862,16 +862,16 @@ def test_extract_track():
     )
     track = dfs.extract_track(df)
 
-    assert track.data[2][23] == approx(3.6284972794399653)
-    assert sum(np.isnan(track.data[2])) == 26
-    assert np.all(track.data[1] == df.latitude.values)
+    assert track[2].values[23] == approx(3.6284972794399653)
+    assert sum(np.isnan(track[2].to_numpy())) == 26
+    assert np.all(track[1].to_numpy() == df.latitude.values)
 
     items = ["Sign. Wave Height", "Wind speed"]
     track2 = dfs.extract_track(csv_file, items=items)
-    assert track2.data[2][23] == approx(3.6284972794399653)
+    assert track2[2].values[23] == approx(3.6284972794399653)
 
     track3 = dfs.extract_track(csv_file, method="inverse_distance")
-    assert track3.data[2][23] == approx(3.6469911492412463)
+    assert track3[2].values[23] == approx(3.6469911492412463)
 
 
 def test_extract_bad_track():
diff --git a/tests/test_dfsu_layered.py b/tests/test_dfsu_layered.py
index 7ff53425..c87bbe4e 100644
--- a/tests/test_dfsu_layered.py
+++ b/tests/test_dfsu_layered.py
@@ -11,7 +11,7 @@ def test_read_simple_3d():
     filename = os.path.join("tests", "testdata", "basin_3d.dfsu")
     ds = mikeio.read(filename)
 
-    assert len(ds.data) == 3
+    assert ds.to_numpy().shape[0] == 3
     assert len(ds.items) == 3
 
     assert ds.items[0].name != "Z coordinate"
@@ -24,7 +24,7 @@ def test_read_simple_2dv():
 
     ds = dfs.read()
 
-    assert len(ds.data) == 3
+    assert ds.to_numpy().shape[0] == 3
     assert len(ds.items) == 3
 
     assert ds.items[0].name != "Z coordinate"
@@ -207,7 +207,7 @@ def test_read_and_select_single_element_dfsu_3d():
 
     selds = ds.isel(idx=1739, axis=1)
 
-    assert selds.data[0].shape == (3,)
+    assert selds[0].shape == (3,)
 
 
 def test_n_layers():
diff --git a/tests/test_generic.py b/tests/test_generic.py
index 94398b2c..9680e4db 100644
--- a/tests/test_generic.py
+++ b/tests/test_generic.py
@@ -19,9 +19,9 @@ def test_add_constant(tmpdir):
 
     scaled = mikeio.read(outfilename)
 
-    orgvalue = org.data[0][0]
+    orgvalue = org[0].values[0]
     expected = orgvalue + 100.0
-    scaledvalue = scaled.data[0][0]
+    scaledvalue = scaled[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -35,9 +35,9 @@ def test_multiply_constant(tmpdir):
 
     scaled = mikeio.read(outfilename)
 
-    orgvalue = org.data[0][0]
+    orgvalue = org[0].values[0]
     expected = orgvalue * 1.5
-    scaledvalue = scaled.data[0][0]
+    scaledvalue = scaled[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -51,14 +51,14 @@ def test_multiply_constant_single_item_number(tmpdir):
 
     scaled = mikeio.read(outfilename)
 
-    orgvalue_speed = org.data[0][0][0]
+    orgvalue_speed = org[0].values[0][0]
     expected_speed = orgvalue_speed * 1.5
-    scaledvalue_speed = scaled.data[0][0][0]
+    scaledvalue_speed = scaled[0].values[0][0]
     assert scaledvalue_speed == pytest.approx(expected_speed)
 
-    orgvalue_dir = org.data[1][0][0]
+    orgvalue_dir = org[1].values[0, 0]
     expected_dir = orgvalue_dir
-    scaledvalue_dir = scaled.data[1][0][0]
+    scaledvalue_dir = scaled[1].values[0, 0]
     assert scaledvalue_dir == pytest.approx(expected_dir)
 
 
@@ -172,9 +172,9 @@ def test_linear_transform(tmpdir):
 
     scaled = mikeio.read(outfilename)
 
-    orgvalue = org.data[0][0]
+    orgvalue = org[0].values[0]
     expected = orgvalue * 1.5 - 20.0
-    scaledvalue = scaled.data[0][0]
+    scaledvalue = scaled[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -188,9 +188,9 @@ def test_linear_transform_dfsu(tmpdir):
 
     scaled = mikeio.read(outfilename)
 
-    orgvalue = org.data[0][0]
+    orgvalue = org[0].values[0]
     expected = orgvalue * 1.5 - 20.0
-    scaledvalue = scaled.data[0][0]
+    scaledvalue = scaled[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -205,9 +205,9 @@ def test_sum_dfsu(tmpdir):
 
     summed = mikeio.read(outfilename)
 
-    orgvalue = org.data[0][0]
+    orgvalue = org[0].values[0]
     expected = orgvalue * 2
-    scaledvalue = summed.data[0][0]
+    scaledvalue = summed[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -223,7 +223,7 @@ def test_diff_dfsu(tmpdir):
     diffed = mikeio.read(outfilename)
 
     expected = 0.0
-    scaledvalue = diffed.data[0][0]
+    scaledvalue = diffed[0].values[0]
     assert scaledvalue == pytest.approx(expected)
 
 
@@ -308,7 +308,7 @@ def test_concat_keep(tmpdir):
 
         # read outfile
         dso = mikeio.read(outfilename)
-        df_o = pd.DataFrame(dso.data[0], index=dso.time)
+        df_o = pd.DataFrame(dso[0].to_numpy(), index=dso.time)
 
         """ handle data (always keep two data in memory to compare in overlapping period) """
         # !!! checks below solely consider one item !!
@@ -317,12 +317,12 @@ def test_concat_keep(tmpdir):
 
             # just store current (=last) data in first loop. no check required
             if i == 0:
-                df_last = pd.DataFrame(dsi.data[0], index=dsi.time)
+                df_last = pd.DataFrame(dsi[0].to_numpy(), index=dsi.time)
             else:
                 # move previously last to first
                 df_first = df_last.copy()
                 # overwrite last with new / current data
-                df_last = pd.DataFrame(dsi.data[0], index=dsi.time)
+                df_last = pd.DataFrame(dsi[0].to_numpy(), index=dsi.time)
 
                 # find overlapping timesteps via merge
                 overlap_idx = pd.merge(
diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py
index 36a99347..58b2350b 100644
--- a/tests/test_interpolation.py
+++ b/tests/test_interpolation.py
@@ -28,9 +28,9 @@ def test_interp2d():
     dati = interp2d(ds, elem_ids, weights)
     assert isinstance(dati, Dataset)
     assert np.all(dati.shape == (ds.n_timesteps, npts))
-    assert dati.data[0][0, 0] == 8.262675285339355
+    assert dati[0].values[0, 0] == 8.262675285339355
 
-    dat = ds.data[0]  # first item, all time steps
+    dat = ds[0].to_numpy()  # first item, all time steps
     dati = interp2d(dat, elem_ids, weights)
     assert isinstance(dati, np.ndarray)
     assert dati.size == ds.n_timesteps * npts
@@ -38,7 +38,7 @@ def test_interp2d():
 
     elem_ids, weights = dfs.get_2d_interpolant(xy, n_nearest=3)
 
-    dat = ds.data[0][0, :]  # a single time step
+    dat = ds[0].values[0, :]  # a single time step
     dati = interp2d(dat, elem_ids, weights)
     assert isinstance(dati, np.ndarray)
     assert dati.size == npts
@@ -52,7 +52,7 @@ def test_interp2d_same_points():
     xy = dfs.element_coordinates[:npts, 0:2]
     elem_ids, weights = dfs.get_2d_interpolant(xy, n_nearest=4)
     assert np.max(weights) <= 1.0
-    dat = ds.data[0][0, :]
+    dat = ds[0].values[0, :]
     dati = interp2d(dat, elem_ids, weights)
     assert np.all(dati == dat[:npts])
 
@@ -66,10 +66,10 @@ def test_interp2d_outside():
     xy[0, :] = [2, 50]
     xy[1, :] = [3, 51]
     elem_ids, weights = dfs.get_2d_interpolant(xy, n_nearest=4)
-    dati = interp2d(ds.data[0][0, :], elem_ids, weights)
+    dati = interp2d(ds[0].values[0, :], elem_ids, weights)
     assert np.all(np.isnan(dati))
     elem_ids, weights = dfs.get_2d_interpolant(xy, n_nearest=4, extrapolate=True)
-    dati = interp2d(ds.data[0][0, :], elem_ids, weights)
+    dati = interp2d(ds[0].values[0, :], elem_ids, weights)
     assert np.all(~np.isnan(dati))
 
 
@@ -86,7 +86,7 @@ def test_interp_itemstep():
     xy[4, :] = [5, 54]
     elem_ids, weights = dfs.get_2d_interpolant(xy, n_nearest=1)
 
-    dat = ds.data[0][0, :]
+    dat = ds[0].values[0, :]
     dati = _interp_itemstep(dat, elem_ids, weights)
     assert len(dati) == npts
     assert dati[0] == 8.262675285339355
diff --git a/tests/test_main.py b/tests/test_main.py
index 5c61801b..061490ac 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -7,7 +7,7 @@ def test_read_dfs0_generic_read():
     filename = r"tests/testdata/random.dfs0"
 
     res = mikeio.read(filename)
-    data = res.data
+    data = res.to_numpy()
 
     assert len(data) == 2
 
@@ -17,7 +17,7 @@ def test_read_dfs1_generic_read():
     filename = r"tests/testdata/random.dfs1"
 
     res = mikeio.read(filename)
-    data = res.data[0]
+    data = res[0].to_numpy()
     assert data.shape == (100, 3)  # time, x