This repository was archived by the owner on Oct 24, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ class DataTree(
87
87
88
88
def __init__ (
89
89
self ,
90
- data : Optional [ Dataset | DataArray ] = None ,
90
+ data : Dataset | DataArray = None ,
91
91
parent : DataTree = None ,
92
92
children : Mapping [str , DataTree ] = None ,
93
93
name : str = None ,
@@ -119,7 +119,7 @@ def __init__(
119
119
super ().__init__ (children = children )
120
120
self .name = name
121
121
self .parent = parent
122
- self .ds = data # type: ignore[assignment]
122
+ self .ds = data
123
123
124
124
@property
125
125
def name (self ) -> str | None :
@@ -128,6 +128,11 @@ def name(self) -> str | None:
128
128
129
129
@name .setter
130
130
def name (self , name : str | None ) -> None :
131
+ if name is not None :
132
+ if not isinstance (name , str ):
133
+ raise TypeError ("node name must be a string or None" )
134
+ if "/" in name :
135
+ raise ValueError ("node names cannot contain forward slashes" )
131
136
self ._name = name
132
137
133
138
@property
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ def test_unnamed(self):
63
63
dt = DataTree ()
64
64
assert dt .name is None
65
65
66
+ def test_bad_names (self ):
67
+ with pytest .raises (TypeError ):
68
+ DataTree (name = 5 )
69
+
70
+ with pytest .raises (ValueError ):
71
+ DataTree (name = "folder/data" )
72
+
66
73
67
74
class TestFamilyTree :
68
75
def test_setparent_unnamed_child_node_fails (self ):
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ Bug fixes
38
38
By `Matt McCormick <https://github.com/thewtex >`_.
39
39
- Fix netCDF encoding for compression (:pull: `95 `)
40
40
By `Joe Hamman <https://github.com/jhamman >`_.
41
+ - Added validity checking for node names (:pull: `106 `)
42
+ By `Tom Nicholas <https://github.com/TomNicholas >`_.
41
43
42
44
Documentation
43
45
~~~~~~~~~~~~~
You can’t perform that action at this time.
0 commit comments