camel
                                
                                
                                
                                    camel copied to clipboard
                            
                            
                            
                        "Not Subscriptable" Error in a very simple wrapper for numpy.float64 that simply converts it to float:
"Not Subscriptable" Error in a very simple wrapper for numpy.float64 that simply converts it to float:
Hi there,
All I am doing is this:
@registry.loader('np_float64_mine', version=1) def _load_np_float64(obj, version, **kwargs): return np.float64(obj)
But, I get this strange error.
resolvers = self.yaml._implicit_resolvers.get(value[0],[]) TypeError: 'float' object is not subscriptable
Things work great for many more complex things, like np.ndarray, etc. But, for some reason, it's trying to take the length of singletons(?) like np.float64.
If I am doing something stupid, I apologizie, and would appreciate if you'd point me in the right direction.
Below, for reference, is a full MRE of the error.
import camel
try: import numpy as np _have_numpy = True except Exception: have_numpy = False warnings.warn("Numpy not found. Won't provide numpy-related methods.")
from camel import Camel, CamelRegistry registry = CamelRegistry()
if _have_numpy:
## THIS DUMP IS WHERE THE ERROR LIES. 
@registry.dumper(np.float64, 'np_float64_mine', version=1)
def _dump_np_float64(obj, **kwargs):
    return float(obj)
@registry.loader('np_float64_mine', version=1)
def _load_np_float64(obj, version, **kwargs):
    return np.float64(obj)
## everything else, works great, example, this - 
@registry.dumper(np.ndarray, 'np_ndarray_mine', version=1)
def _dump_np_ndarray(obj, **kwargs):
    return([ str(obj.dtype), obj.tolist() ] )
@registry.loader('np_ndarray_mine', version=1)
def _load_np_ndarray(obj, version, **kwargs):
    (strdtype, obj)=obj
    return np.asarray(obj, dtype=strdtype)
def _test(item): print("ORIGINAL ITEM and its type:") print(item) print(f"{type(item)=}") dumped = dumps(item) print("DUMPED ITEM:") print(dumped) print("original item followed by LOAD OF DUMPED ITEM:") print(item) print(loads(dumped)) print("=================================================================================================")
def _tests(): _test(np.float64(345)
Update: A float64 object by itself dumps just fine. But, if you try to dump [1, np.float64(33)], that's when we get that error.