Skip to content

Commit

Permalink
fix: output constituent from get and pop as copy (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley authored Jul 26, 2023
1 parent b8f2a2a commit 81b0507
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyTMD/io/constituents.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
constituents.py
Written by Tyler Sutterley (03/2023)
Written by Tyler Sutterley (07/2023)
Basic tide model constituent class
PYTHON DEPENDENCIES:
Expand All @@ -10,11 +10,13 @@
https://numpy.org/doc/stable/user/numpy-for-matlab-users.html
UPDATE HISTORY:
Updated 07/2023: output constituent from get and pop as copy
Updated 03/2023: add basic variable typing to function inputs
Written 12/2022
"""
from __future__ import division, annotations

import copy
import numpy as np

class constituents:
Expand Down Expand Up @@ -64,7 +66,8 @@ def get(self, field: str):
constituent: np.ndarray
Tide model constituent (complex form)
"""
return getattr(self, field)
constituent = getattr(self, field)
return copy.copy(constituent)

def pop(self, field: str):
"""
Expand All @@ -83,7 +86,7 @@ def pop(self, field: str):
self.fields.remove(field)
constituent = getattr(self, field)
delattr(self, field)
return constituent
return copy.copy(constituent)

def update(self, field: str, constituent: np.ndarray):
"""
Expand Down

0 comments on commit 81b0507

Please sign in to comment.