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

deepcopy of subint HDU #173

Open
luojing1211 opened this issue Jun 8, 2020 · 1 comment
Open

deepcopy of subint HDU #173

luojing1211 opened this issue Jun 8, 2020 · 1 comment

Comments

@luojing1211
Copy link
Collaborator

Since we modified the new of subint HDU class. It will raise error when deepcopying it. Is there a way to make the deepcopy work again?

import copy
>>> f = open('../../Projects/test_data/CHIME_B1937+21_grid01_beam_7_58464_79458.fits', 'r')
>>> type(f.ih)
    scintillometry.io.psrfits.hdu.PSRSubintHDU
>>> copy.deepcopy(f.ih)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/scintillometry-0.0.dev374-py3.6.egg/scintillometry/io/psrfits/hdu.py in __new__(cls, hdu, primary_hdu, verify)
    232         try:
--> 233             mode = primary_hdu.obs_mode
    234             cls = subint_map[mode]

AttributeError: 'NoneType' object has no attribute 'obs_mode'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-12-4531c13cc470> in <module>
----> 1 copy.deepcopy(f.ih)

~/anaconda3/lib/python3.6/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181 
    182     # If is its own copy, don't memoize.

~/anaconda3/lib/python3.6/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    272     if deep and args:
    273         args = (deepcopy(arg, memo) for arg in args)
--> 274     y = func(*args)
    275     if deep:
    276         memo[id(x)] = y

~/anaconda3/lib/python3.6/copyreg.py in __newobj__(cls, *args)
     86 
     87 def __newobj__(cls, *args):
---> 88     return cls.__new__(cls, *args)
     89 
     90 def __newobj_ex__(cls, args, kwargs):

~/.local/lib/python3.6/site-packages/scintillometry-0.0.dev374-py3.6.egg/scintillometry/io/psrfits/hdu.py in __new__(cls, hdu, primary_hdu, verify)
    234             cls = subint_map[mode]
    235         except AttributeError:
--> 236             raise ValueError("need a primary HDU to determine the mode.")
    237         except KeyError:
    238             raise ValueError("'{}' is not a valid mode.".format(mode))

ValueError: need a primary HDU to determine the mode.
@mhvk
Copy link
Owner

mhvk commented Jun 8, 2020

Ah, yes, I had a similar problem while setting up pickling for baseband - mhvk/baseband@9563dca#diff-a3f78791258cf574889e85e114fb8192 - basically ensure that all arguments have defaults and that a non-default argument is only required if the class is actually the one that selects the different cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants