Liu Hui <liuhui1...@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.