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

BUG: pysat.utils.listify breaks for empty list input [] #830

Closed
rstoneback opened this issue Jul 1, 2021 · 0 comments · Fixed by #831
Closed

BUG: pysat.utils.listify breaks for empty list input [] #830

rstoneback opened this issue Jul 1, 2021 · 0 comments · Fixed by #831

Comments

@rstoneback
Copy link
Collaborator

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. pysat.utils.listify([])
  2. See error

From unit testing

iterable = []

    def listify(iterable):
        """Returns a flattened list of iterable if not already a list
    
        Parameters
        ----------
        iterable : iter-like
            An iterable object that will be wrapped within a list
    
        Returns
        -------
        list
            An enclosing 1-D list of iterable if not already a list
    
        """
    
        arr_iter = np.asarray(iterable)
        if arr_iter.shape == ():
            list_iter = [arr_iter.tolist()]
        elif arr_iter.shape[0] >= 1:
            list_iter = arr_iter.flatten().tolist()
    
>       return list_iter
E       UnboundLocalError: local variable 'list_iter' referenced before assignment

Expected behavior
Should work fine.

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

Desktop (please complete the following information):

  • OS: macOS
  • Version python 3.7
  • Other details about your setup that could be relevant

Additional context
As is, code will break on any input that doesn't match the two checks.

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

Successfully merging a pull request may close this issue.

1 participant