question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'fix_inputs' does not work with empty 'values' dictionary

See original GitHub issue

Description

“Fixing” inputs of a model with an empty values dictionary results in a model that cannot be evaluated due to an undefined variable.

Expected behavior

I would expect mf model to function just like m given that there are no inputs fixed.

Actual behavior

The code crashed due to an undefined variable.

Steps to Reproduce

In [1]: from astropy.modeling import models
   ...: m = models.Identity(2)
   ...: mf = models.fix_inputs(m, {})
   ...: mf(1, 2)
   ...:
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-31-4a2d25efb6e6> in <module>
      2 m = models.Identity(2)
      3 mf = models.fix_inputs(m, {})
----> 4 mf(1, 2)

.../lib/python3.8/site-packages/astropy/modeling/core.py in __call__(self, *args, **kw)
   2818             return outputs
   2819         else:
-> 2820             return self._evaluate(*args, **kw)
   2821
   2822     def _evaluate(self, *args, **kw):

.../lib/python3.8/site-packages/astropy/modeling/core.py in _evaluate(self, *args, **kw)
   2880                 # subindsorted, subvalsorted = list(zip(*subargs))
   2881             # The substitutions must be inserted in order
-> 2882             for ind, val in subargs:
   2883                 newargs.insert(ind, val)
   2884             return self.left(*newargs, **kw)

UnboundLocalError: local variable 'subargs' referenced before assignment

System Details

macOS-10.15.7-x86_64-i386-64bit
Python 3.8.5 (default, Sep  4 2020, 02:22:02)
[Clang 10.0.0 ]
Numpy 1.20.1
astropy 4.2
Scipy 1.6.1
Matplotlib 3.3.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
perrygreenfieldcommented, Mar 1, 2021

I imagine the fix is pretty simple. Test for an empty dictionary and if that is the case, just return the original model.

0reactions
mcaracommented, Mar 1, 2021

Is there a reason why not to fix the code so that subargs is defined and code works on empty dictionaries as well. Of course we can bypass the entire code if we see an empty list but I worry (without understanding the code in depth) that this may be an indication of another problem with the code. What do you think @perrygreenfield ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pythonic way to check empty dictionary and empty values
Isnt there an unique way to check if a or b have values? You can check all(collection_b.values()) but that wont work for collection_a...
Read more >
Python - Test for Empty Dictionary Value List - GeeksforGeeks
This is another way in which we can solve the problem. In this, we can check for each key if all values are...
Read more >
Python: Check if a Dictionary is Empty (5 Ways!) - Datagy
Learn how to check if a Python dictionary is empty, including five different ways to do this, including using simple booleans and its ......
Read more >
Create Empty Dictionary in Python (5 Easy Ways) - FavTutor
Python empty dictionary means that it does not contain any key-value pair elements. To create an empty dictionary in this example, we can ......
Read more >
Dictionaries in Python - Real Python
In this Python dictionaries tutorial, you'll cover the basic characteristics and learn how to access and manage dictionary data. Once you have finished...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found