8000 add a separate error for names with wrong type and remove such keys by lukaspie · Pull Request #638 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add a separate error for names with wrong type and remove such keys #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ message:
If you use this software, please cite it using the
metadata from this file.
type: software
version: 0.10.6
version: 0.10.7
authors:
- given-names: Sherjeel
family-names: Shabih
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/data/NXtest.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
</group>
<group type="NXdata" name="specified_group" nameType="specified">
<doc>A group with a name and nameType="specified".</doc>
<field name="specified_field" type="NX_FLOAT" units="NX_ANY">
<attribute name="specified_attr_in_field"/>
<field name="specified_field" nameType="specified" type="NX_FLOAT" units="NX_ANY">
<attribute name="specified_attr_in_field" nameType="specified"/>
</field>
<attribute name="specified_attr"/>
</group>
Expand Down
8 changes: 1 addition & 7 deletions src/pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,12 @@ def transfer_data_into_template(
for entry_name in entry_names:
helpers.write_nexus_def_to_entry(data, entry_name, nxdl_name)
if not skip_verify:
valid, keys_to_remove = validate_dict_against(
valid = validate_dict_against(
nxdl_name,
data,
ignore_undocumented=ignore_undocumented,
)

# remove attributes that belong to non-existing fields

for key in keys_to_remove:
# data.__delitem__(key)
del data[key]

if fail and not valid:
raise ValidationFailed(
"The data does not match the given NXDL. "
Expand Down
72 changes: 40 additions & 32 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import re
from datetime import datetime, timezone
from enum import Enum
from enum import Enum, auto
from functools import lru_cache
from typing import Any, Callable, List, Optional, Tuple, Union, Sequence, cast

Expand All @@ -46,30 +46,32 @@


class ValidationProblem(Enum):
UnitWithoutDocumentation = 1
InvalidEnum = 2
OpenEnumWithNewItem = 3
MissingRequiredGroup = 4
MissingRequiredField = 5
MissingRequiredAttribute = 6
InvalidType = 7
InvalidDatetime = 8
IsNotPosInt = 9
ExpectedGroup = 10
MissingDocumentation = 11
MissingUnit = 12
ChoiceValidationError = 13
UnitWithoutField = 14
AttributeForNonExistingField = 15
BrokenLink = 16
FailedNamefitting = 17
NXdataMissingSignalData = 18
NXdataMissingAxisData = 19
NXdataAxisMismatch = 20
KeyToBeRemoved = 21
InvalidConceptForNonVariadic = 22
ReservedSuffixWithoutField = 23
ReservedPrefixInWrongContext = 24
UnitWithoutDocumentation = auto()
InvalidEnum = auto()
OpenEnumWithNewItem = auto()
MissingRequiredGroup = auto()
MissingRequiredField = auto()
MissingRequiredAttribute = auto()
InvalidType = auto()
InvalidDatetime = auto()
IsNotPosInt = auto()
ExpectedGroup = auto()
ExpectedField = auto()
MissingDocumentation = auto()
MissingUnit = auto()
ChoiceValidationError = auto()
UnitWithoutField = auto()
AttributeForNonExistingField = auto()
BrokenLink = auto()
FailedNamefitting = auto()
NXdataMissingSignalData = auto()
NXdataMissingAxisData = auto()
NXdataAxisMismatch = auto()
KeyToBeRemoved = auto()
InvalidConceptForNonVariadic = auto()
ReservedSuffixWithoutField = auto()
ReservedPrefixInWrongContext = auto()
InvalidNexusTypeForNamedConcept = auto()


class Collector:
Expand All @@ -96,9 +98,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
f"The value at {path} does not match with the enumerated items from the open enumeration: {value}."
)
elif log_type == ValidationProblem.MissingRequiredGroup:
logger.warning(f"The required group, {path}, hasn't been supplied.")
logger.error(f"The required group, {path}, hasn't been supplied.")
elif log_type == ValidationProblem.MissingRequiredField:
logger.warning(
logge 8000 r.error(
f"The data entry corresponding to {path} is required "
"and hasn't been supplied by the reader.",
)
Expand All @@ -118,9 +120,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
f"The value at {path} should be a positive int, but is {value}."
)
elif log_type == ValidationProblem.ExpectedGroup:
logger.warning(
f"Expected a group at {path} but found a field or attribute."
)
logger.error(f"Expected a group at {path} but found a field or attribute.")
elif log_type == ValidationProblem.ExpectedField:
logger.error(f"Expected a field at {path} but found a group.")
elif log_type == ValidationProblem.MissingDocumentation:
if "@" in path.rsplit("/")[-1]:
logger.warning(f"Attribute {path} written without documentation.")
Expand All @@ -140,7 +142,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
"but the field does not exist."
)
elif log_type == ValidationProblem.BrokenLink:
logger.warning(f"Broken link at {path} to {value}")
logger.warning(f"Broken link at {path} to {value}.")
elif log_type == ValidationProblem.FailedNamefitting:
logger.warning(f"Found no namefit of {path} in {value}.")
elif log_type == ValidationProblem.NXdataMissingSignalData:
Expand All @@ -152,7 +154,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
f"Length of axis {path} does not match to {value} in dimension {args[0]}"
)
elif log_type == ValidationProblem.KeyToBeRemoved:
logger.warning(f"The attribute {path} will not be written.")
logger.warning(f"The {value} {path} will not be written.")
elif log_type == ValidationProblem.InvalidConceptForNonVariadic:
value = cast(Any, value)
log_text = f"Given {value.type} name '{path}' conflicts with the non-variadic name '{value}'"
Expand All @@ -169,6 +171,12 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
if value != "<unknown>":
log_text += f" It is only valid in the context of {value}."
logger.error(log_text)
elif log_type == ValidationProblem.InvalidNexusTypeForNamedConcept:
value = cast(Any, value)
logger.error(
f"The type ('{args[0] if args else '<unknown>'}') of the given concept '{path}' "
f"conflicts with another existing concept of the same name, which is of type '{value.type}'."
)

def collect_and_log(
self,
Expand Down
Loading
Loading
0