Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve speed of hasattr on IDS structures
Replace `_path` (which constructs the path including AoS indices) with the static `metadata.path_string` when an attribute cannot be found.

Speeds up the following sample from 110ms to 0.5ms (200x gain):

```python
import timeit
import imas

cp = imas.IDSFactory().core_profiles()
cp.profiles_1d.resize(1000)
def totime():
    hasattr(cp.profiles_1d[999], "xyz")
print(timeit.repeat(totime, number=1000))
```

**Changed behaviour:**
Before: `AttributeError: IDS structure 'profiles_1d[999]' has no attribute 'xyz'`
After: `AttributeError: IDS structure 'profiles_1d' has no attribute 'xyz'`

Since the index of an AoS is not relevant for whether an attribute exists or not, I believe this is not a problem.
  • Loading branch information
maarten-ic committed Aug 5, 2026
commit a3c7ed69186576c5277434a77f251064822404cd
2 changes: 1 addition & 1 deletion imas/ids_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, parent: IDSBase, metadata: IDSMetadata):
def __getattr__(self, name):
if name not in self._children:
raise AttributeError(
f"IDS structure '{self._path}' has no attribute '{name}'"
f"IDS structure '{self.metadata.path_string}' has no attribute '{name}'"
)
# Create child node
child_meta = self._children[name]
Expand Down