Skip to content

Commit f4f9520

Browse files
committed
convert data types to avoid issues between np1 and np2
1 parent e5f9287 commit f4f9520

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/pynxtools/dataconverter/helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
132132
"and hasn't been supplied by the reader.",
133133
)
134134
elif log_type == ValidationProblem.InvalidType:
135+
type_names = [
136+
f"{t.__module__}.{t.__name__}"
137+
if t.__module__ != "builtins"
138+
else t.__name__
139+
for t in value
140+
]
135141
logger.warning(
136-
f"The value at {path} should be one of the following Python types: {value}"
137-
f", as defined in the NXDL as {args[0] if args else '<unknown>'}."
142+
f"The value at {path} should be one of the following Python types: "
143+
f"{', '.join(type_names)}, "
144+
f"as defined in the NXDL as {args[0] if args else '<unknown>'}."
138145
)
139146
elif log_type == ValidationProblem.InvalidDatetime:
140147
logger.warning(

tests/dataconverter/test_validation.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def listify_template(data_dict: Template):
419419
),
420420
[
421421
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/anamethatRENAMES[anamethatichangetothis]"
422-
" should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
422+
" should be one of the following Python types: int, numpy.integer, as defined in "
423423
"the NXDL as NX_INT."
424424
],
425425
id="variadic-field-str-instead-of-int",
@@ -432,7 +432,7 @@ def listify_template(data_dict: Template):
432432
),
433433
[
434434
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
435-
"t_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
435+
"t_value should be one of the following Python types: int, numpy.integer, as defined in "
436436
"the NXDL as NX_INT."
437437
],
438438
id="string-instead-of-int",
@@ -444,7 +444,7 @@ def listify_template(data_dict: Template):
444444
"NOT_TRUE_OR_FALSE",
445445
),
446446
[
447-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: (<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
447+
"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."
448448
],
449449
id="string-instead-of-bool",
450450
),
@@ -456,7 +456,7 @@ def listify_template(data_dict: Template):
456456
),
457457
[
458458
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should"
459-
" be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
459+
" be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
460460
],
461461
id="list-of-int-str-instead-of-int",
462462
),
@@ -468,7 +468,7 @@ def listify_template(data_dict: Template):
468468
),
469469
[
470470
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should be"
471-
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
471+
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
472472
],
473473
id="array-of-float-instead-of-int",
474474
),
@@ -520,7 +520,7 @@ def listify_template(data_dict: Template):
520520
np.complex128(0),
521521
),
522522
[
523-
"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."
523+
"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."
524524
],
525525
id="complex-instead-of-float",
526526
),
@@ -531,7 +531,7 @@ def listify_template(data_dict: Template):
531531
"0",
532532
),
533533
[
534-
"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."
534+
"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."
535535
],
536536
id="str-instead-of-number",
537537
),
@@ -543,7 +543,7 @@ def listify_template(data_dict: Template):
543543
),
544544
[
545545
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one"
546-
" of the following Python types: (<class 'str'>, <class 'numpy.character'>), as"
546+
" of the following Python types: str, numpy.character, as"
547547
" defined in the NXDL as NX_CHAR."
548548
],
549549
id="wrong-type-ndarray-instead-of-char",
@@ -627,9 +627,9 @@ def listify_template(data_dict: Template):
627627
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value", 3
628628
),
629629
[
630-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one of the following Python types:"
631-
" (<class 'str'>, <class 'numpy.character'>),"
632-
" as defined in the NXDL as NX_CHAR."
630+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be "
631+
"one of the following Python types: str, numpy.character, "
632+
"as defined in the NXDL as NX_CHAR."
633633
],
634634
id="int-instead-of-chars",
635635
),
@@ -684,7 +684,7 @@ def listify_template(data_dict: Template):
684684
),
685685
[
686686
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be "
687-
"one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL "
687+
"one of the following Python types: float, numpy.floating, as defined in the NXDL "
688688
"as NX_FLOAT."
689689
],
690690
id="array-of-str-instead-of-float",
@@ -1076,7 +1076,7 @@ def listify_template(data_dict: Template):
10761076
),
10771077
[
10781078
"The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
1079-
"one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
1079+
"one of the following Python types: int, numpy.integer, as "
10801080
"defined in the NXDL as NX_INT."
10811081
],
10821082
id="concept-name-given-for-nonvariadic-field-wrong-type",
@@ -1130,7 +1130,7 @@ def listify_template(data_dict: Template):
11301130
["0", 1, 2],
11311131
),
11321132
[
1133-
"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.",
1133+
"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.",
11341134
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
11351135
],
11361136
id="wrong-type-array-in-attribute",
@@ -1438,7 +1438,7 @@ def listify_template(data_dict: Template):
14381438
),
14391439
[
14401440
"The value at /ENTRY[my_entry]/duration should be"
1441-
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
1441+
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
14421442
],
14431443
id="baseclass-wrong-dtype",
14441444
),
@@ -1741,7 +1741,7 @@ def listify_template(data_dict: Template):
17411741
[
17421742
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value "
17431743
"should be one of the following Python types: "
1744-
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
1744+
"int, numpy.integer, as defined in the "
17451745
"NXDL as NX_INT."
17461746
],
17471747
id="appdef-compressed-wrong-type",
@@ -1750,7 +1750,7 @@ def listify_template(data_dict: Template):
17501750
alter_dict(
17511751
TEMPLATE,
17521752
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value",
1753-
{"compress": np.int64(2), "strength": 11},
1753+
{"compress": 2, "strength": 11},
17541754
),
17551755
[
17561756
"Compression strength for /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value = "
@@ -1788,7 +1788,7 @@ def listify_template(data_dict: Template):
17881788
[
17891789
"The value at /ENTRY[my_entry]/SAMPLE[sample1]]/changer_position "
17901790
"should be one of the following Python types: "
1791-
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
1791+
"int, class 'numpy.integer, as defined in the "
17921792
"NXDL as NX_INT."
17931793
],
17941794
id="baseclass-compressed-wrong-type",

0 commit comments

Comments
 (0)