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

eval, repr, and empty Instruments instantiation error #851

Closed
rstoneback opened this issue Jul 20, 2021 · 3 comments · Fixed by #918
Closed

eval, repr, and empty Instruments instantiation error #851

rstoneback opened this issue Jul 20, 2021 · 3 comments · Fixed by #918
Assignees
Labels
Milestone

Comments

@rstoneback
Copy link
Collaborator

rstoneback commented Jul 20, 2021

Describe the bug
Empty instrument object doesn't have a string representation that leads back to itself.

To Reproduce
Steps to reproduce the behavior:

In [1]: import pysat                                                                                                                                                                                                        

In [2]: inst = pysat.Instrument()                                                                                                                                                                                           

In [3]: repr(inst)                                                                                                                                                                                                          
Out[3]: "pysat.Instrument(platform='', name='', tag='', inst_id='', clean_level='clean', pad=None, orbit_info={}, inst_module=None, custom=[], **{})"

In [4]: eval(repr(inst))                                                                                                                                                                                                    
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-c961af2d6bbf> in <module>
----> 1 eval(repr(inst))

<string> in <module>

~/Code/pysat/pysat/_instrument.py in __init__(self, platform, name, tag, inst_id, clean_level, update_files, pad, orbit_info, inst_module, directory_format, file_format, temporary_file_list, strict_time_flag, ignore_empty_files, labels, custom, **kwargs)
    263 
    264                 # Look to module for instrument functions and defaults
--> 265                 self._assign_attrs(by_name=True, tag=self.tag,
    266                                    inst_id=self.inst_id)
    267             elif (platform is None) and (name is None):

~/Code/pysat/pysat/_instrument.py in _assign_attrs(self, by_name, inst_module, tag, inst_id)
   1210                 user_modules = pysat.params['user_modules']
   1211                 if self.platform not in user_modules.keys():
-> 1212                     raise KeyError('unknown platform supplied: {:}'.format(
   1213                         self.platform))
   1214 

KeyError: 'unknown platform supplied: '

Expected behavior
Another empty Instrument object like we were able to instantiate to begin with.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Version Python 3.8
  • Other details about your setup that could be relevant

Additional context
Add any other context about the problem here.

@rstoneback rstoneback added the bug label Jul 26, 2021
@rstoneback rstoneback added this to the 3.1.0 Release milestone Jul 28, 2021
@jklenzing
Copy link
Member

Requires merge of #903 since new instrument tests will be added

@jklenzing jklenzing self-assigned this Sep 30, 2021
@jklenzing
Copy link
Member

jklenzing commented Oct 4, 2021

For a blank instrument, self._assign_attrs should be called as a default function. After instantiation, instruments with platform=None will be reset to platform=''. This triggers self_assign_attrs(by_name=True) on subsequent runs, such as when eval is called. This is the source of the errors, as multiple checks are run under by_name=True that assume a module must be present under inst_module.

@jklenzing
Copy link
Member

Closing with merge of #918

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

Successfully merging a pull request may close this issue.

2 participants