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

Dataframe method fails with return in facets #68

Open
lambdamusic opened this issue Sep 10, 2020 · 0 comments
Open

Dataframe method fails with return in facets #68

lambdamusic opened this issue Sep 10, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@lambdamusic
Copy link
Member

%%dsldf
search publications 
return in "facets" funders 
return in "facets" research_orgs

leads to

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/internals/construction.py in _list_to_arrays(data, columns, coerce_float, dtype)
    495     try:
--> 496         result = _convert_object_array(
    497             content, columns, dtype=dtype, coerce_float=coerce_float

~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/internals/construction.py in _convert_object_array(content, columns, coerce_float, dtype)
    579             # caller's responsibility to check for this...
--> 580             raise AssertionError(
    581                 f"{len(columns)} columns passed, passed data had "

AssertionError: 1 columns passed, passed data had 20 columns

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-69-c85bc5dbe030> in <module>
----> 1 get_ipython().run_cell_magic('dsldf', '', 'search publications \nreturn in "facets" funders \nreturn in "facets" research_orgs\n')

~/Envs/jupyterlab/lib/python3.8/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2369             with self.builtin_trap:
   2370                 args = (magic_arg_s, cell)
-> 2371                 result = fn(*args, **kwargs)
   2372             return result
   2373 

<decorator-gen-127> in dsldf(self, line, cell)

~/Envs/jupyterlab/lib/python3.8/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/Envs/jupyterlab/lib/python3.8/site-packages/dimcli/jupyter/magics.py in dsldf(self, line, cell)
     69                 print("Sorry - DSL to dataframe magic methods work only with `search` queries.")
     70                 return None
---> 71             data = self._handle_query(line).as_dataframe()
     72             self.shell.user_ns[self.results_var] = data
     73             return data

~/Envs/jupyterlab/lib/python3.8/site-packages/dimcli/core/api.py in as_dataframe(self, key)
    711 
    712         if not self.json.get("errors"):
--> 713             return self.df_factory.df_simple(self.json, key)
    714 
    715 

~/Envs/jupyterlab/lib/python3.8/site-packages/dimcli/core/dataframe_factory.py in df_simple(self, data, key)
     46                     output = pd.DataFrame.from_dict(data[valid_key])
     47             elif type(data[valid_key]) == dict: # top level dict, use keys as index
---> 48                 output = pd.DataFrame.from_dict(data[valid_key], orient="index", columns=[valid_key])
     49             else: # no list, then make one and try to return everything
     50                 output = pd.DataFrame.from_dict([data])

~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/frame.py in from_dict(cls, data, orient, dtype, columns)
   1245             raise ValueError("only recognize index or columns for orient")
   1246 
-> 1247         return cls(data, index=index, columns=columns, dtype=dtype)
   1248 
   1249     def to_numpy(self, dtype=None, copy=False) -> np.ndarray:

~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    472                     if is_named_tuple(data[0]) and columns is None:
    473                         columns = data[0]._fields
--> 474                     arrays, columns = to_arrays(data, columns, dtype=dtype)
    475                     columns = ensure_index(columns)
    476 

~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/internals/construction.py in to_arrays(data, columns, coerce_float, dtype)
    459         return [], []  # columns if columns is not None else []
    460     if isinstance(data[0], (list, tuple)):
--> 461         return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype)
    462     elif isinstance(data[0], abc.Mapping):
    463         return _list_of_dict_to_arrays(

~/Envs/jupyterlab/lib/python3.8/site-packages/pandas/core/internals/construction.py in _list_to_arrays(data, columns, coerce_float, dtype)
    498         )
    499     except AssertionError as e:
--> 500         raise ValueError(e) from e
    501     return result
    502 

ValueError: 1 columns passed, passed data had 20 columns
@lambdamusic lambdamusic added the bug Something isn't working label Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant