Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store_data modifies input data structure #994

Open
jameswilburlewis opened this issue Aug 28, 2024 · 1 comment
Open

store_data modifies input data structure #994

jameswilburlewis opened this issue Aug 28, 2024 · 1 comment
Labels
enhancement New feature or request Performance pytplot Issues involving the pytplot package

Comments

@jameswilburlewis
Copy link
Contributor

With this code:

from pytplot import store_data

tp_data={'x':[1,2,3], 'y':[4,5,6]}

store_data('foo',data=tp_data)
store_data('bar',data=tp_data)

the second store_data() call fails because the previous call modified tp_data:

 File "/Users/jwl/PycharmProjects/pyspedas/pyspedas/utilities/tests/tplot_wildcard_tests.py", line 37, in test_tindex_byname
    store_data('bar',data=tp_data)
  File "/Users/jwl/PycharmProjects/PyTplot/pytplot/store_data.py", line 140, in store_data
    values = np.array(data.pop('y'))
KeyError: 'y'

See also: #654

@jameswilburlewis jameswilburlewis added enhancement New feature or request pytplot Issues involving the pytplot package Performance labels Aug 29, 2024
@jameswilburlewis
Copy link
Contributor Author

The default should probably be to make a deep copy of the input structure before modifying anything. But for performance reasons (time and memory consumption), it might be good to add a "no_copy" option that defaults to False, allowing store_data to skip the copy for the sake of efficiency. I think most usages could probably use no_copy safely....but still, we should default to safety rather than efficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Performance pytplot Issues involving the pytplot package
Projects
None yet
Development

No branches or pull requests

1 participant