[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, an
From: |
Jack Kamm |
Subject: |
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots |
Date: |
Fri, 18 Aug 2023 16:09:06 -0700 |
Liu Hui <liuhui1610@gmail.com> writes:
> Hi,
>
> Thank you for the patch!
Thanks for your feedback, I've incorporated it into
https://github.com/jackkamm/org-mode/tree/python-results-revisited-2023
More specifically, here:
https://github.com/jackkamm/org-mode/commit/af1d18314073446045395ff7a3d1de0303e92586
> Do we need to limit the table/list size by default, or handle them
> only with relevant result type (e.g. `table/list')? Dataframe/array
> are often large.
I've updated the patch so that Dataframe/Array are converted to table
only when ":results table" is explicitly set now. If ":results table" is
not set, they will be returned as string by default.
So code blocks that return large dataframes/arrays can continue to be
safely run.
Note I did make an additional change to Numpy array default behavior:
Previously, numpy arrays would be returned as table, but get mangled
when they were very large, e.g.:
#+begin_src python
import numpy as np
return np.zeros((30,40))
#+end_src
#+RESULTS:
| (0 0 0 ... 0 0 0) | (0 0 0 ... 0 0 0) | (0 0 0 ... 0 0 0) | ... | (0 0 0
... 0 0 0) | (0 0 0 ... 0 0 0) | (0 0 0 ... 0 0 0) |
But now, Numpy array is returned in string form by default, in the same
format as in Jupyter:
#+begin_src python
import numpy as np
return np.zeros((30,40))
#+end_src
#+RESULTS:
: array([[0., 0., 0., ..., 0., 0., 0.],
: [0., 0., 0., ..., 0., 0., 0.],
: [0., 0., 0., ..., 0., 0., 0.],
: ...,
: [0., 0., 0., ..., 0., 0., 0.],
: [0., 0., 0., ..., 0., 0., 0.],
: [0., 0., 0., ..., 0., 0., 0.]])
>> + if isinstance(result, pandas.DataFrame):
>> + result = [[''] + list(result.columns), None] + \
>
> Here we can use '{}'.format(df.index.name) to show the name of index
Patch has been updated to print the index name when it is non-None.
> Maybe `org-babel-python--def-format-value' can be evaluated only once
> in the session mode? It would shorten the string sent to the python
> shell, where temp files are used for long strings.
Patch has been updated to evaluate `org-babel-python--def-format-value'
once per session.
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, (continued)
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/19
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/19
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/22
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/17
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/18
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Liu Hui, 2023/08/17
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots,
Jack Kamm <=
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Liu Hui, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/20
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Liu Hui, 2023/08/21
- Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Jack Kamm, 2023/08/22
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots, Ihor Radchenko, 2023/08/17
- Prev by Date:
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots
- Next by Date:
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots
- Previous by thread:
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots
- Next by thread:
Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots
- Index(es):