-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
Bug Description
When using pandas 3.0, StringArray objects can be passed to ParameterNodeAtInstant.__getitem__, but StringArray is not hashable and can't be used as a dictionary key.
Error
TypeError: unhashable type: 'StringArray'
at policyengine_core/parameters/parameter_node_at_instant.py:61:
return self._children[key]Root Cause
In pandas 3.0, string columns use StringDtype by default, producing StringArray objects instead of numpy object arrays. The check on line 57 only handles numpy.ndarray:
if isinstance(key, numpy.ndarray):
return parameters.VectorialParameterNodeAtInstant.build_from_node(self)[key]
return self._children[key] # Fails if key is StringArrayProposed Fix
Also check for pandas ExtensionArrays or convert StringArray to numpy array before using as dict key:
import pandas as pd
if isinstance(key, (numpy.ndarray, pd.api.extensions.ExtensionArray)):
return parameters.VectorialParameterNodeAtInstant.build_from_node(self)[key]
return self._children[key]Related
This is separate from #427 which fixed enum encoding with StringDtype Series.
Metadata
Metadata
Assignees
Labels
No labels