Skip to content

Commit 9933a6c

Browse files
fix ImmutableGeophiresInputParameters pickling serialization
1 parent 0d748d8 commit 9933a6c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/geophires_x_client/geophires_input_parameters.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ def __deepcopy__(self, memo):
161161
memo[id(self)] = self
162162
return self
163163

164+
def __getstate__(self) -> dict:
165+
"""
166+
Prepare the object's state for pickling.
167+
Converts the mappingproxy to a regular dict, which is pickleable.
168+
"""
169+
state = self.__dict__.copy()
170+
# Convert mappingproxy to dict for serialization
171+
state['params'] = dict(self.params)
172+
return state
173+
174+
def __setstate__(self, state: dict):
175+
"""
176+
Restore the object's state after unpickling.
177+
Converts the dict back to a mappingproxy to maintain immutability.
178+
"""
179+
# Convert dict back to mappingproxy
180+
state['params'] = MappingProxyType(state['params'])
181+
# Restore the instance's dictionary
182+
self.__dict__.update(state)
183+
164184
def as_file_path(self) -> Path:
165185
"""
166186
Creates a temporary file representation of the parameters on demand.

0 commit comments

Comments
 (0)