Repository: DHI/mikeio

Issue:
attribute not registered after rename?
**Describe the bug**
I get unexpected behavior after renaming an item of a mikeio dataset.

**Screenshots**
![image](https://user-images.githubusercontent.com/29595985/189924839-123fdc1e-ff2c-47af-906f-0b32f6cdd0ff.png)


**Expected behavior**
I expected to also be able to do `ds.WLtot` after renaming.

**System information:**
 - Python 3.10.6
 - MIKE 1.1.0


Discussion:

Patch:
diff --git a/mikeio/dataset.py b/mikeio/dataset.py
index 2e5ffa72..e8fd3869 100644
--- a/mikeio/dataset.py
+++ b/mikeio/dataset.py
@@ -673,8 +673,8 @@ class Dataset(DataUtilsMixin, TimeSeries, collections.abc.MutableMapping):
             da = ds._data_vars.pop(old_name)
             da.name = new_name
             ds._data_vars[new_name] = da
-            self._del_name_attr(old_name)
-            self._set_name_attr(new_name, da)
+            ds._del_name_attr(old_name)
+            ds._set_name_attr(new_name, da)
 
         return ds
 


Test patch:
diff --git a/tests/test_dataset.py b/tests/test_dataset.py
index 95940e59..76e66720 100644
--- a/tests/test_dataset.py
+++ b/tests/test_dataset.py
@@ -596,7 +596,7 @@ def test_interp_time():
     assert dsi[0].shape == (73, 10, 3)
 
     dsi2 = ds.interp_time(freq="2H")
-    assert dsi2.timestep == 2*3600
+    assert dsi2.timestep == 2 * 3600
 
 
 def test_interp_time_to_other_dataset():
@@ -1325,6 +1325,21 @@ def test_concat_by_time_2():
     assert ds4.is_equidistant
 
 
+def test_renamed_dataset_has_updated_attributes(ds1: mikeio.Dataset):
+    assert hasattr(ds1, "Foo")
+    assert isinstance(ds1.Foo, mikeio.DataArray)
+    ds2 = ds1.rename(dict(Foo="Baz"))
+    assert not hasattr(ds2, "Foo")
+    assert hasattr(ds2, "Baz")
+    assert isinstance(ds2.Baz, mikeio.DataArray)
+
+    # inplace version
+    ds1.rename(dict(Foo="Baz"), inplace=True)
+    assert not hasattr(ds1, "Foo")
+    assert hasattr(ds1, "Baz")
+    assert isinstance(ds1.Baz, mikeio.DataArray)
+
+
 def test_merge_by_item():
     ds1 = mikeio.read("tests/testdata/tide1.dfs1")
     ds2 = mikeio.read("tests/testdata/tide1.dfs1")