Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/pynxtools/data/NXtest.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
</field>
</group>
<group type="NXdata" name="NXODD_name">
<field name="anamethatRENAMES" nametype="any" type="NX_INT" units="NX_UNITLESS"/>
Comment thread
rettigl marked this conversation as resolved.
Outdated
<field name="float_value" type="NX_FLOAT" optional="true" units="NX_ENERGY">
<doc>A dummy entry for a float value.</doc>
</field>
<field name="number_value" type="NX_NUMBER" optional="true" units="NX_ENERGY">
<doc>A dummy entry for a number value.</doc>
</field>
<field name="bool_value" type="NX_BOOLEAN" required="true" units="NX_UNITLESS">
<doc>A dummy entry for a bool value.</doc>
</field>
Expand All @@ -53,6 +57,12 @@
<item value="3rd type" />
<item value="4th type" />
</enumeration>
<attribute name="array" type="NX_INT">
<enumeration>
<item value="[0, 1, 2]" />
<item value="[2, 3, 4]" />
</enumeration>
</attribute>
</field>
</group>
<group type="NXnote" name="required_group">
Expand Down
20 changes: 13 additions & 7 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
)
elif log_type == ValidationProblem.InvalidType:
logger.warning(
f"The value at {path} should be one of: {value}"
f"The value at {path} should be one of the following Python types: {value}"
f", as defined in the NXDL as {args[0] if args else '<unknown>'}."
)
elif log_type == ValidationProblem.InvalidDatetime:
Expand Down Expand Up @@ -158,9 +158,9 @@ def collect_and_log(
"NX_ANY",
):
return
if self.logging:
if self.logging and path + str(log_type) + str(value) not in self.data:
self._log(path, log_type, value, *args, **kwargs)
self.data.add(path)
self.data.add(path + str(log_type) + str(value))

def has_validation_problems(self):
"""Returns True if there were any validation problems."""
Expand Down Expand Up @@ -584,7 +584,11 @@ def is_value_valid_element_of_enum(value, elist) -> Tuple[bool, list]:
# Not to be confused with `np.byte` and `np.ubyte`, these store
# an integer of `8bit` and `unsigned 8bit` respectively.
np_bytes = (np.bytes_,)
np_char = (np.str_, np.bytes_) # Only numpy Unicode string and Byte string
np_char = (
np.str_,
np.bytes_,
np.chararray,
) # Only numpy Unicode string and Byte string
np_bool = (np.bool_,)
np_complex = (np.complex64, np.complex128, np.cdouble, np.csingle, np.complex_)
NEXUS_TO_PYTHON_DATA_TYPES = {
Expand Down Expand Up @@ -647,9 +651,11 @@ def check_all_children_for_callable(
return False
if isinstance(objects, list):
# Handles list and list of list
return all([type(elem) in accepted_types for elem in objects])
if isinstance(objects, np.ndarray):
return any([np.issubdtype(objects.dtype, type_) for type_ in accepted_types])
tmp_arr = np.array(objects)
elif isinstance(objects, np.ndarray):
tmp_arr = objects
if tmp_arr is not None:
return any([np.issubdtype(tmp_arr.dtype, type_) for type_ in accepted_types])

return False

Expand Down
6 changes: 5 additions & 1 deletion src/pynxtools/dataconverter/readers/example/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def read(
# outputs with --generate-template for a provided NXDL file
if (
k.startswith("/ENTRY[entry]/required_group")
or k == "/ENTRY[entry]/optional_parent/req_group_in_opt_group"
or k
in (
"/ENTRY[entry]/optional_parent/req_group_in_opt_group",
"/ENTRY[entry]/NXODD_name[nxodd_name]/anamethatRENAMES[anamethatrenames]",
)
or k.startswith("/ENTRY[entry]/OPTIONAL_group")
):
continue
Expand Down
5 changes: 4 additions & 1 deletion tests/data/dataconverter/readers/example/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"float_value_units": "nm",
"int_value": -3,
"int_value_units": "eV",
"number_value": 3,
"number_value_units": "eV",
"posint_value": 7,
"posint_value_units": "kg",
"definition": "NXtest",
Expand All @@ -17,5 +19,6 @@
"date_value_units": "",
"required_child": 1,
"optional_child": 1,
"@version": "1.0"
"@version": "1.0",
"@array": [0, 1, 2]
}
Loading