From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id iAvcIRvl3WRP0AAASxT56A (envelope-from ) for ; Thu, 17 Aug 2023 11:15:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id ECT2IBvl3WSPXgEAG6o9tA (envelope-from ) for ; Thu, 17 Aug 2023 11:15:07 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0851F3E2E5 for ; Thu, 17 Aug 2023 11:15:07 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=eRmOhrgY; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1692263707; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=QmLAVmyT4F9/NusYQhdvaVU5/6V0V+Ac1TcYumyan9s=; b=WfJKqyXi1sDDDugHU0SMQRDnfchwsYlPRNzD7QwkQktSg9CFzvqLJNWH24pUZ8xRFUYSgb u5DvxppbWYVGTR+rAvvckgH/zkNidK2KJwixfGpC5ScyudjZ+Ywdb1o3c3iWaqHQosM9JU U5LEsBoHyYV3VUxGBKiAymYZwfnPDuJa0oZZDtPG+552JZhc+JUUdX1Qe2ju0ahFie7nPo WYzI61BfiruPKmdIvnuQBK+kdnQNs53t2FbMKCPsWjwSIknanwMRb4Ge3fYFRwC1593sDJ MX43ghisJ5SlDj4BwpOVoed+Esbc/4+lnW2QoJNdsEJAbVID7ZT4o/L9Z+8CDA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=eRmOhrgY; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1692263707; a=rsa-sha256; cv=none; b=OsGXOqycUY41moyKgFsZENp71IkZqe6UrLlHRxdYOV+hJkmXuaIfZdtPUB9OsFR12ztid2 sooGZybvDc2Cb++4l/9zvmxc/5zyOvAHSIgSe0Y+AHAxRXCTouoJfbNS1/7PV8lT26aZL+ YXNZjYeNortoHlEyZVCxE9n1jI/FkRdoAs6L/dxCqt5JRjvvnDCfghBgXuFp4/8npPHTT/ oAXUi0e4qQbQCQighW/Hfav+/ev4mio237XkN7pL9Zc7HDSOWPA4L+2euMUqWxnux5uPyd qCLQFoUTIAdEpCiHakXn1lGDsteimVBO50wABXkAjlp5h6avW2IZLb8iMt+mUg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWZ51-0001Wa-A9; Thu, 17 Aug 2023 05:14:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWZ4z-0001WJ-GG for emacs-orgmode@gnu.org; Thu, 17 Aug 2023 05:14:09 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWZ4w-0001f1-DQ for emacs-orgmode@gnu.org; Thu, 17 Aug 2023 05:14:09 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 943AC240028 for ; Thu, 17 Aug 2023 11:14:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692263642; bh=chGQCJeQeh3tjRQ+Z5Ntn1aVNc9XErfevii9XrAu0SA=; h=MIME-Version:Content-Transfer-Encoding:Date:From:To:Cc:Subject: Message-ID:From; b=eRmOhrgYrPWVVgx/v2l+FwqWLp59n3Y0WZOxymR4I0pGY6cEcv8D22zwpzs/C8wV/ da/nYS1XvgG0ellUtktwgshsGXH3xs50S7kyt9dzgR3HEJh/hlhz+xf9teD05mpevI cLMq6lnCDcUWZ8Apf3imREXKxRgGWwN72G3VfI4ZA+uOG34mtaBjD/XNy63RNadw7K pCKT3euqzMPT+GKdfLdLF3Id6FTR2K4S+/BHKL61XOg454hS2o2mR8j3ksiM2tc4N2 ufe9Xkkp3B/JFmOZXkHGcY86DYWEODdlIjeSCx0Vxd2w/IAFFGCOKQh088n/xzorbV ckmdPzpW0JVBw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RRK7Z0jf8z6tw0; Thu, 17 Aug 2023 11:14:02 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 17 Aug 2023 09:14:02 +0000 From: gerard.vermeulen@posteo.net To: Jack Kamm Cc: Ihor Radchenko , emacs-orgmode@gnu.org, Liu Hui , emacs-orgmode-bounces+gerard.vermeulen=posteo.net@gnu.org Subject: Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots In-Reply-To: <87350i9uwv.fsf@gmail.com> References: <87a5ur6f7w.fsf@gmail.com> <871qg3pc2o.fsf@localhost> <87350i9uwv.fsf@gmail.com> Message-ID: <9948eae293cae8766808778d6390eb64@posteo.net> Received-SPF: pass client-ip=185.67.36.65; envelope-from=gerard.vermeulen@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -8.30 X-Migadu-Queue-Id: 0851F3E2E5 X-Spam-Score: -8.30 X-Migadu-Scanner: mx1.migadu.com X-TUID: fDyk83mS5poc On 17.08.2023 06:04, Jack Kamm wrote: > I attach a 2nd patch implementing this. It also makes ":results table" > the default return type for dict. (Use ":results verbatim" to get the > dict as a string instead). > > I am also putting a branch with these changes here: > https://github.com/jackkamm/org-mode/tree/python-results-revisited-2023 > Happy to see that ob-python gets so much love! Your patches allow anyone to change org-babel-python--def-format-value. For instance, I want to use black to "pretty-print" certain tree-like structures and I have now in my init.el: (with-eval-after-load 'ob-python (setq org-babel-python--def-format-value "\ def __org_babel_python_format_value(result, result_file, result_params): with open(result_file, 'w') as f: if 'graphics' in result_params: result.savefig(result_file) elif 'pp' in result_params: import black f.write(black.format_str(repr(result), mode=black.Mode())) else: if not set(result_params).intersection(\ ['scalar', 'verbatim', 'raw']): try: import pandas except ImportError: pass else: if isinstance(result, pandas.DataFrame): result = [[''] + list(result.columns), None] + \ [[i] + list(row) for i, row in result.iterrows()] elif isinstance(result, pandas.Series): result = list(result.items()) try: import numpy except ImportError: pass else: if isinstance(result, numpy.ndarray): result = result.tolist() f.write(str(result))")) Without your patches I use advice to override org-babel-python-format-session-value, which is worse IMO. This also allows anyone to format for instance AstroPy tables (https://docs.astropy.org/en/stable/table/). I do not know how much this "abuse" of defconst is frowned upon (elisp manual says defconst is advisory), but maybe it can be advertised as a feature. Best regards -- Gerard