Skip to content

Commit 161e982

Browse files
committed
convert data types to avoid issues between np1 and np2
1 parent fb576dd commit 161e982

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/pynxtools/dataconverter/helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,16 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
165165
elif log_type == ValidationProblem.MissingRequiredAttribute:
166166
logger.warning(f"The required attribute {path} hasn't been supplied.")
167167
elif log_type == ValidationProblem.InvalidType:
168+
type_names = [
169+
f"{t.__module__}.{t.__name__}"
170+
if t.__module__ != "builtins"
171+
else t.__name__
172+
for t in value
173+
]
168174
logger.warning(
169-
f"The value at {path} should be one of the following Python types: {value}"
170-
f", as defined in the NXDL as {args[0] if args else '<unknown>'}."
175+
f"The value at {path} should be one of the following Python types: "
176+
f"{', '.join(type_names)}, "
177+
f"as defined in the NXDL as {args[0] if args else '<unknown>'}."
171178
)
172179
elif log_type == ValidationProblem.InvalidDatetime:
173180
logger.warning(

tests/dataconverter/test_validation.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def format_error_message(msg: str) -> str:
443443
),
444444
[
445445
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/anamethatRENAMES[anamethatichangetothis]"
446-
" should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
446+
" should be one of the following Python types: int, numpy.integer, as defined in "
447447
"the NXDL as NX_INT."
448448
],
449449
id="variadic-field-str-instead-of-int",
@@ -456,7 +456,7 @@ def format_error_message(msg: str) -> str:
456456
),
457457
[
458458
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
459-
"t_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
459+
"t_value should be one of the following Python types: int, numpy.integer, as defined in "
460460
"the NXDL as NX_INT."
461461
],
462462
id="string-instead-of-int",
@@ -468,8 +468,7 @@ def format_error_message(msg: str) -> str:
468468
"NOT_TRUE_OR_FALSE",
469469
),
470470
[
471-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: "
472-
"(<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
471+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: bool, numpy.bool, as defined in the NXDL as NX_BOOLEAN."
473472
],
474473
id="string-instead-of-bool",
475474
),
@@ -481,7 +480,7 @@ def format_error_message(msg: str) -> str:
481480
),
482481
[
483482
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should"
484-
" be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
483+
" be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
485484
],
486485
id="list-of-int-str-instead-of-int",
487486
),
@@ -493,7 +492,7 @@ def format_error_message(msg: str) -> str:
493492
),
494493
[
495494
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should be"
496-
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
495+
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
497496
],
498497
id="array-of-float-instead-of-int",
499498
),
@@ -545,7 +544,7 @@ def format_error_message(msg: str) -> str:
545544
np.complex128(0),
546545
),
547546
[
548-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL as NX_FLOAT."
547+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be one of the following Python types: float, numpy.floating, as defined in the NXDL as NX_FLOAT."
549548
],
550549
id="complex-instead-of-float",
551550
),
@@ -556,7 +555,7 @@ def format_error_message(msg: str) -> str:
556555
"0",
557556
),
558557
[
559-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/number_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>, <class 'float'>, <class 'numpy.floating'>), as defined in the NXDL as NX_NUMBER."
558+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/number_value should be one of the following Python types: int, numpy.integer, float, numpy.floating, as defined in the NXDL as NX_NUMBER."
560559
],
561560
id="str-instead-of-number",
562561
),
@@ -568,7 +567,7 @@ def format_error_message(msg: str) -> str:
568567
),
569568
[
570569
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one"
571-
" of the following Python types: (<class 'str'>, <class 'numpy.character'>), as"
570+
" of the following Python types: str, numpy.character, as"
572571
" defined in the NXDL as NX_CHAR."
573572
],
574573
id="wrong-type-ndarray-instead-of-char",
@@ -652,9 +651,9 @@ def format_error_message(msg: str) -> str:
652651
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value", 3
653652
),
654653
[
655-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one of the following Python types:"
656-
" (<class 'str'>, <class 'numpy.character'>),"
657-
" as defined in the NXDL as NX_CHAR."
654+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be "
655+
"one of the following Python types: str, numpy.character, "
656+
"as defined in the NXDL as NX_CHAR."
658657
],
659658
id="int-instead-of-chars",
660659
),
@@ -709,7 +708,7 @@ def format_error_message(msg: str) -> str:
709708
),
710709
[
711710
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be "
712-
"one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL "
711+
"one of the following Python types: float, numpy.floating, as defined in the NXDL "
713712
"as NX_FLOAT."
714713
],
715714
id="array-of-str-instead-of-float",
@@ -1229,7 +1228,7 @@ def format_error_message(msg: str) -> str:
12291228
),
12301229
[
12311230
"The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
1232-
"one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
1231+
"one of the following Python types: int, numpy.integer, as "
12331232
"defined in the NXDL as NX_INT."
12341233
],
12351234
id="concept-name-given-for-nonvariadic-field-wrong-type",
@@ -1280,7 +1279,7 @@ def format_error_message(msg: str) -> str:
12801279
["0", 1, 2],
12811280
),
12821281
[
1283-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT.",
1282+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT.",
12841283
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
12851284
],
12861285
id="wrong-type-array-in-attribute",
@@ -1588,7 +1587,7 @@ def format_error_message(msg: str) -> str:
15881587
),
15891588
[
15901589
"The value at /ENTRY[my_entry]/duration should be"
1591-
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
1590+
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
15921591
],
15931592
id="baseclass-wrong-dtype",
15941593
),
@@ -1897,7 +1896,7 @@ def format_error_message(msg: str) -> str:
18971896
[
18981897
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value "
18991898
"should be one of the following Python types: "
1900-
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
1899+
"int, numpy.integer, as defined in the "
19011900
"NXDL as NX_INT."
19021901
],
19031902
id="appdef-compressed-wrong-type",
@@ -1906,7 +1905,7 @@ def format_error_message(msg: str) -> str:
19061905
alter_dict(
19071906
TEMPLATE,
19081907
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value",
1909-
{"compress": np.int64(2), "strength": 11},
1908+
{"compress": 2, "strength": 11},
19101909
),
19111910
[
19121911
"Compression strength for /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value = "
@@ -1944,7 +1943,7 @@ def format_error_message(msg: str) -> str:
19441943
[
19451944
"The value at /ENTRY[my_entry]/SAMPLE[sample1]]/changer_position "
19461945
"should be one of the following Python types: "
1947-
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
1946+
"int, class 'numpy.integer, as defined in the "
19481947
"NXDL as NX_INT."
19491948
],
19501949
id="baseclass-compressed-wrong-type",

0 commit comments

Comments
 (0)