Problem with array from series if datatype is unknown
Sometimes the datatype of series is not known (output of a function with no static typing). This is a problem in some operations, for example converting to an array:
Input > info(times)
Output > ((name: 'times'), (type: 'Series'), (scalar: false), (numeric: null), (datatype: null), (dimensionality: '[time]'), (units: 'angstrom * unified_atomic_mass_unit ** 0.5 / electron_volt ** 0.5'), ('group UUID': 'c44a37e21fcd4e68a9640e465994cfa4'), ('model UUID': '6224b06cc6cc4bca90599361fb4af880'), ('node UUID': 'acdba90bbdfe4ce4aa0f1f49c730e9fc'), ('node ID': 27), ('parent IDs': (20, 21)), ('node state': 'COMPLETED'), ('created on': '2025-03-25T18:40:03+01:00'), ('updated on': '2025-03-25T18:48:36+01:00'), ('grammar version': 32), ('data schema version': 7), ('python version': '3.9.16 (main, Oct 16 2024, 02:42:27)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-18)]'), (category: 'interactive'), (fworker: null), (dupefinder: true), ('reservation ID': null), ('number of launches': 1), ('number of archived launches': 0), (launch_dir: ('fireworks-launches/launcher_2025-03-25-17-48-35-542499',)), ('archived launch_dir': ()), (runtime_secs: 0.246568), ('runtime_secs total': 0.246568))
Input > times[:100]
Output > (times: 0.0, 0.9822694750253275, 1.964538950050655, 2.9468084250759823, 3.92907790010131, 4.911347375126637, 5.893616850151965, 6.875886325177293, 7.85815580020262, 8.840425275227947, 9.822694750253275, 10.804964225278603, 11.78723370030393, 12.769503175329257, 13.751772650354585, 14.734042125379911, 15.71631160040524, 16.698581075430567, 17.680850550455894, 18.663120025481224, 19.64538950050655, 20.627658975531876, 21.609928450557206, 22.592197925582532, 23.57446740060786, 24.556736875633188, 25.539006350658514, 26.52127582568384, 27.50354530070917, 28.485814775734497, 29.468084250759823, 30.450353725785153, 31.43262320081048, 32.41489267583581, 33.397162150861135, 34.37943162588646, 35.36170110091179, 36.343970575937114, 37.32624005096245, 38.30850952598777, 39.2907790010131, 40.273048476038426, 41.25531795106375, 42.23758742608908, 43.21985690111441, 44.20212637613974, 45.184395851165064, 46.16666532619039, 47.14893480121572, 48.13120427624104, 49.113473751266376, 50.0957432262917, 51.07801270131703, 52.060282176342355, 53.04255165136768, 54.02482112639301, 55.00709060141834, 55.98936007644367, 56.97162955146899, 57.95389902649432, 58.936168501519646, 59.91843797654497, 60.900707451570305, 61.88297692659563, 62.86524640162096, 63.847515876646284, 64.82978535167162, 65.81205482669694, 66.79432430172227, 67.77659377674759, 68.75886325177292, 69.74113272679826, 70.72340220182357, 71.70567167684891, 72.68794115187423, 73.67021062689956, 74.6524801019249, 75.63474957695021, 76.61701905197555, 77.59928852700087, 78.5815580020262, 79.56382747705152, 80.54609695207685, 81.52836642710218, 82.5106359021275, 83.49290537715284, 84.47517485217816, 85.45744432720349, 86.43971380222882, 87.42198327725414, 88.40425275227948, 89.3865222273048, 90.36879170233013, 91.35106117735545, 92.33333065238078, 93.31560012740611, 94.29786960243143, 95.28013907745677, 96.26240855248209, 97.24467802750742) [angstrom * unified_atomic_mass_unit ** 0.5 / electron_volt ** 0.5]
Input > times[:100]:array
Exiting
Traceback (most recent call last):
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 306, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session_manager.py", line 186, in get_model_value
return getattr(self.session.get_model(*args, uuid=self.uuid, **kwargs), 'value', '')
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session.py", line 149, in get_model
self.process_models(model_str, model_path, active_uuid=uuid)
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session.py", line 205, in process_models
model, uuid = self._process_model(uuid, strn, path, active_uuid=active_uuid)
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session.py", line 548, in _process_model
model = tx_get_model(model_src, deferred_mode=True,
File "jupyter-tensorflow-2023-10-10/lib64/python3.9/site-packages/textx/metamodel.py", line 699, in model_from_str
p(model, self)
File "virtmat-tools/vre-language/src/virtmat/language/constraints/processors.py", line 34, in check_types_processor
_ = obj.type_
File "/usr/lib64/python3.9/functools.py", line 993, in __get__
val = self.func(instance)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 211, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 52, in print_type
_ = par.type_
File "/usr/lib64/python3.9/functools.py", line 993, in __get__
val = self.func(instance)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 211, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 66, in print_parameter_type
return self.param.type_
File "/usr/lib64/python3.9/functools.py", line 993, in __get__
val = self.func(instance)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 215, in wrapper
raise TextXError(str(err), **get_location_context(obj)) from err
textx.exceptions.TextXError: None:1:2033: => 'times[:100]:array'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 306, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session_manager.py", line 206, in process_input
output = self.get_model_value(model_str=f'print({input_str})')
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 308, in wrapper
process_error(err)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 296, in process_error
raise err.__cause__
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 211, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 484, in iterable_property_type
ret_type = str if self.name_ else get_sliced_type(self)
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 362, in get_sliced_type
return get_array_type(type_, {'datatype': type_, 'datalen': (size_,)})
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 340, in get_array_type
raise err
File "virtmat-tools/vre-language/src/virtmat/language/constraints/typechecks.py", line 336, in get_array_type
mtype = next(m for m, d in dtypemap.items() if datatype and issubclass(datatype, d))
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 306, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/cli/run_session.py", line 98, in main
mgr.main_loop()
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session_manager.py", line 161, in main_loop
self.interact(banner='Welcome to textS/textM. Type %help for some help.',
File "/usr/lib64/python3.9/code.py", line 232, in interact
more = self.push(line)
File "/usr/lib64/python3.9/code.py", line 258, in push
more = self.runsource(source, self.filename)
File "virtmat-tools/vre-language/src/virtmat/language/interpreter/session_manager.py", line 173, in runsource
need_inp = self.process_input(source)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 341, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 306, in wrapper
return func(*args, **kwargs)
File "virtmat-tools/vre-language/src/virtmat/language/cli/__init__.py", line 38, in texts
clargs.func(clargs)
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 341, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "jupyter-tensorflow-2023-10-10/bin/texts", line 8, in <module>
sys.exit(texts())
File "virtmat-tools/vre-language/src/virtmat/language/utilities/errors.py", line 341, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
It does not matter with slice or without slice, i.e. times:array
also crashes. If times
has known datatype
then the error does not occur.