-
Notifications
You must be signed in to change notification settings - Fork 127
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
Richer run
command output
#735
Comments
Prototype this. I agree that a simple string isn't sufficient sometimes. |
Also, thinking about this more, provided that we can maintain backwards compatibility, being able to represent for jupyter notebooks would be really powerful as well. I'm thinking something like this for returning the command output as different array types. The point of this is, always return string, but allow output as native python types (array, list, pandas, etc.) class CommandOutput():
def __init__(self, cmd, string_):
self._cmd_output = string_
self._cmd = cmd
self._str_parse = None
def __repr__(self):
# consider adding ipython representation
return self._cmd_output
def __str__(self):
return self._cmd_output
def _parse(self):
"""Prettify the command output into a more readable string
Something along the lines of: https://docs.python.org/3/library/pprint.html
"""
if _cmd in ['ELIST', 'NLIST']:
# parse_xlist_command()
pass
def _parse_xlist_command(self):
return # parse ...
def as_array(self):
"""Return the command output to a numpy array"""
if self._cmd in ['PRNSOL']:
# do something
else:
raise TypeError("This command output cannot be converted to a ``numpy.ndarray``")
return array
def as_dataframe(self):
"""Return the command output to a ``pandas.DataFrame`` if available."""
if self._cmd in ['PRNSOL']:
# do something
else:
raise TypeError("This command output cannot be converted to a ``pandas.dataframe``")
return df |
Current situation
Commands like
ELIST
,NLIST
, etc. returns a string, which is fine. Other commands such asPRNSOL
and similar, returns also a string.This is the default behavior.
Proposition
I believe that output from the commands should be "richer". For example, we should parse commands like
ELIST
to output a table.To not break compatibility, we could make an object (
CommandOutput
?) which its representation (__repr__
) is the command output, hence we could keep the current code.Progress
CommandOutput
implementation. Situation: Almost ready.Richer command output #791
CommandOutputListing
. Features to list, numpy and dataframe conversion for listing commands.Feat/Richer cmd output for listing commands #816
FLIST
andDLIST
. Blocker for Feature/Boundary conditions plotting #741.ELIST
andNLIST
. Important requested feature, difficult implementation because of the main scenarios available.Example
This could be used in the output of
run
:The text was updated successfully, but these errors were encountered: