Skip to content

Commit

Permalink
Extend nx type (#435)
Browse files Browse the repository at this point in the history
* Include NX_CHAR_OR_NUMBER as NX valid type.

* Include XRD in the list of Plugin test.

* update numpy type

* dix tests.

* update resolve change request from Lukas.
  • Loading branch information
RubelMozumder authored Sep 26, 2024
1 parent 5f1cd37 commit d192fd6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/plugin_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- plugin: pynxtools-xps
branch: main
tests_to_run: tests/.
- plugin: pynxtools-xrd
branch: main
tests_to_run: tests/.
# - plugin: pynxtools-apm
# branch: main
# tests_to_run: tests/.
Expand Down
54 changes: 44 additions & 10 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,32 +577,66 @@ def is_value_valid_element_of_enum(value, elist) -> Tuple[bool, list]:
NUMPY_FLOAT_TYPES = (np.half, np.float16, np.single, np.double, np.longdouble)
NUMPY_INT_TYPES = (np.short, np.intc, np.int_)
NUMPY_UINT_TYPES = (np.ushort, np.uintc, np.uint)

# np int for np version 1.26.0
np_int = (
np.intc,
np.int_,
np.intp,
np.int8,
np.int16,
np.int32,
np.int64,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
np.unsignedinteger,
np.signedinteger,
)
np_float = (np.float16, np.float32, np.float64, np.floating)
np_bytes = (np.bytes_, np.byte, np.ubyte)
np_char = (np.str_, np.char.chararray, *np_bytes)
np_bool = (np.bool_,)
np_complex = (np.complex64, np.complex128, np.cdouble, np.csingle)
NEXUS_TO_PYTHON_DATA_TYPES = {
"ISO8601": (str,),
"NX_BINARY": (bytes, bytearray, np.byte, np.ubyte, np.ndarray),
"NX_BOOLEAN": (bool, np.ndarray, np.bool_),
"NX_CHAR": (str, np.ndarray, np.char.chararray),
"NX_BINARY": (
bytes,
bytearray,
np.ndarray,
*np_bytes,
),
"NX_BOOLEAN": (bool, np.ndarray, *np_bool),
"NX_CHAR": (str, np.ndarray, *np_char),
"NX_DATE_TIME": (str,),
"NX_FLOAT": (float, np.ndarray, np.floating),
"NX_INT": (int, np.ndarray, np.signedinteger),
"NX_FLOAT": (float, np.ndarray, *np_float),
"NX_INT": (int, np.ndarray, *np_int),
"NX_UINT": (np.ndarray, np.unsignedinteger),
"NX_NUMBER": (
int,
float,
np.ndarray,
np.signedinteger,
np.unsignedinteger,
np.floating,
*np_int,
*np_float,
dict,
),
"NX_POSINT": (
int,
np.ndarray,
np.signedinteger,
), # > 0 is checked in is_valid_data_field()
"NX_COMPLEX": (complex, np.ndarray, np.cdouble, np.csingle),
"NX_COMPLEX": (complex, np.ndarray, *np_complex),
"NXDL_TYPE_UNAVAILABLE": (str,), # Defaults to a string if a type is not provided.
"NX_CHAR_OR_NUMBER": (
str,
int,
float,
np.ndarray,
*np_char,
*np_int,
*np_float,
dict,
),
}


Expand Down
16 changes: 13 additions & 3 deletions tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ def fixture_filled_test_data(template, tmp_path):
]
TEMPLATE["optional"]["/@default"] = "Some NXroot attribute"

# "The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
# "t_value should be one of: (<class 'int'>, <cla"
# "ss 'numpy.ndarray'>, <class 'numpy.signedinteger'>),"
# " as defined in the NXDL as NX_INT."


# pylint: disable=too-many-arguments
@pytest.mark.parametrize(
Expand All @@ -274,9 +279,14 @@ def fixture_filled_test_data(template, tmp_path):
),
(
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
"t_value should be one of: (<class 'int'>, <cla"
"ss 'numpy.ndarray'>, <class 'numpy.signedinteger'>),"
" as defined in the NXDL as NX_INT."
"t_value should be one of: (<class 'int'>, <class 'numpy"
".ndarray'>, <class 'numpy.int32'>, <class 'numpy.int64'>,"
" <class 'numpy.int64'>, <class 'numpy.int8'>, <class 'numpy"
".int16'>, <class 'numpy.int32'>, <class 'numpy.int64'>, "
"<class 'numpy.uint8'>, <class 'numpy.uint16'>, <class 'numpy"
".uint32'>, <class 'numpy.uint64'>, <class 'numpy.unsignedi"
"nteger'>, <class 'numpy.signedinteger'>), as defined in "
"the NXDL as NX_INT."
),
id="string-instead-of-int",
),
Expand Down

0 comments on commit d192fd6

Please sign in to comment.