From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 6JZyHcwD4mQjKgEASxT56A (envelope-from ) for ; Sun, 20 Aug 2023 14:15:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id OKjpHMwD4mTdAAEAauVa8A (envelope-from ) for ; Sun, 20 Aug 2023 14:15:08 +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 05E16517B4 for ; Sun, 20 Aug 2023 14:15:08 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=JQT8t66z; 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=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1692533708; a=rsa-sha256; cv=none; b=e9l8jPS1n7Otm/uYeBXhx6KanJ2i0A8TDhE8swgPfXjfg7SCBEuxwabLA0aAm9nXvt1293 oEQbZYa7En4tC3pSMj6fFtM+dNR/rLv4KxsD8MFi5G2Ai34u+CNtgI18KvwAcFt0IaydsG 4P+Qar4XAhu6naVGkF+tgiMYgdCWNGYjT6pmm2mGf1nUpDQsmpcbBPgYibxDbUnQTYyUCl jHUty89Rr9uGc+FoF1RHhtsdimPL+16nqrLy1VuPmSveF/OzF5zcYShmQ1YdQutxyd0EwX 5HIUqcY3nedLpoK5eU8N64yVtOg0v7eZxvnRcRDDgyQ0nS6vy7VJTCPLDftnFA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=JQT8t66z; 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=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1692533708; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=YO/gkJUHSnPd5FWzRN3NnI3EoNCZxG0jivuRqQ+hp/Y=; b=Ptp+UFPpIR+uYbHDVV7fnxvVllbpo36KXM78PQCnEvIt3V4LGEEnd56pL2QDj9qIqm2XiZ DdBuLibm8RDO9PLREzyc6wWJ/LEARrcDYtSFEef4GctLPvnKVD3LBdM03/VC36BETaMNCJ 0dPd3k6bUy9LWl7w6kW/I7V9U5Om7/tLoGbzC39OSqg244tgYOES9um1gj2/tqYX4l6GVf GUQShp17TX1eMnpFzgk4DH6bXwyVYW7pxGeMlxt9TtHelcyjWvhGqfYK/sNc8gWuRZWOQE 37ofRM0EjRgtqONXfFG0HjfrAvqHB1sM830JyLZ4bZLFHZaUbsWn45YekNdD4g== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXhJr-0000Zg-9x; Sun, 20 Aug 2023 08: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 1qXhJp-0000ZE-16 for emacs-orgmode@gnu.org; Sun, 20 Aug 2023 08:14:09 -0400 Received: from mail-vk1-xa30.google.com ([2607:f8b0:4864:20::a30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qXhJm-000597-SP for emacs-orgmode@gnu.org; Sun, 20 Aug 2023 08:14:08 -0400 Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-48d109dc6beso70069e0c.1 for ; Sun, 20 Aug 2023 05:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692533645; x=1693138445; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YO/gkJUHSnPd5FWzRN3NnI3EoNCZxG0jivuRqQ+hp/Y=; b=JQT8t66zgp5PXsiTweS3WJWyaNl/HmsKLLXdSlZPZ1sCKXwYqaRfnF23st55zYNBIw b4PukadCst4c/uiEMxNIsG/Ow5Zh3jubTiAFNo6NAEf/Qbn0fRRbEofz4A1FjWG0lBBx BlRlzyU0/sP4BIU9WzXD/HPgh/jE2050/JaL0Qe9fcWiwyAMolTyMaWmn0cMZgyVSPya 2IpQwS7uij2utyrKDWdASpvId3TpXZcyE/q9silv0kISdRbVfzqbncQaOKs1BvrD7ern 6te55JbgaKdwtabuuzCAYOfWcwFPVFe7UckFKTqxPQiADXUgDfBdlCqx0I/GGHq5zlcm qK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692533645; x=1693138445; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YO/gkJUHSnPd5FWzRN3NnI3EoNCZxG0jivuRqQ+hp/Y=; b=ZWWtPr0EtjCgTVTiFjqcI1vUfJ7smFp3kKJTAUNWVPpqtsImGqBxW61B008bjInqt8 C6GlzFwTRXN6ta5uyuFjpDdOL4a9z1vcWafD5T6S1Ioqvxse+1cUCpdjGiEFcsSwY43j H5SzuoyWVAeV5zF3Fq3pvGCA2Tm7AhEvPBBFd5yvJU9J24RGlN8G/6S3tHnJE262XQjc FkvYXLyH1G5xDP1dYTH1k/EaNB/CZXQai5mBZkCc7l32xJhbPveZJ7uKtv8eu6ctL6rX aIoZ5x2xJdq+KcaCtFow0jmpn/jzd1OqZgHSgoG5WIp0LgC3luArOVk9HOosCH+75NCN R3CQ== X-Gm-Message-State: AOJu0Yzfe3ligsYjTdj9Lg4ZSF85CVRbp1Q7mdDzn3iA0yqtN6GLvqOO CA0WImqEdaS1RGMF2vf9CR/4HS6Y6X9ar39SDag= X-Google-Smtp-Source: AGHT+IHro6CkC659BC21R6rUd7vddN8GOSayFgNctWbHf3P05dahtAnIPUAZ34X1BxQtpk3nMTWgFRIW2zHXOunzUxk= X-Received: by 2002:a1f:4e01:0:b0:486:de54:b11 with SMTP id c1-20020a1f4e01000000b00486de540b11mr1250655vkb.16.1692533645001; Sun, 20 Aug 2023 05:14:05 -0700 (PDT) MIME-Version: 1.0 References: <87a5ur6f7w.fsf@gmail.com> <87edk0aqy5.fsf@gmail.com> In-Reply-To: <87edk0aqy5.fsf@gmail.com> From: Liu Hui Date: Sun, 20 Aug 2023 20:13:53 +0800 Message-ID: Subject: Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots To: Jack Kamm Cc: emacs-orgmode@gnu.org, Ihor Radchenko Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::a30; envelope-from=liuhui1610@gmail.com; helo=mail-vk1-xa30.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Scanner: mx0.migadu.com X-Spam-Score: -9.57 X-Migadu-Queue-Id: 05E16517B4 X-Migadu-Spam-Score: -9.57 X-TUID: QrTP1W6t6kEm > > 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. Thanks! It would be nice to also support MultiIndex names using `result.index.names', e.g. #+begin_src python :results table import numpy as np import pandas as pd df = pd.DataFrame({ "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], "B": ["one", "one", "two", "three", "two", "two", "one", "three"], "C": np.random.randn(8), "D": np.random.randn(8)}) return df.groupby(["A", "B"]).agg('sum').round(3) #+end_src Another problem is the display of objects like datetime, e.g. #+begin_src python :results table import pandas as pd s = pd.Series(range(3), index=pd.date_range("2000", freq="D", periods=3)) return s.to_frame() #+end_src #+RESULTS: | | 0 | | |-----------+-------------------------------+---| | Timestamp | (2000-01-01 00:00:00 freq= D) | 0 | | Timestamp | (2000-01-02 00:00:00 freq= D) | 1 | | Timestamp | (2000-01-03 00:00:00 freq= D) | 2 | #+begin_src python from pathlib import Path import numpy as np return {'a': 1, 'path': Path('/'), 'array': np.zeros(3)} #+end_src #+RESULTS: | a | 1 | | | path | PosixPath | (/) | | array | array | ((0 0 0)) | I think these objects need to be shown in a single column rather than two. Besides, if the python code becomes too complex finally, I think maintaining the python code outside the ob-python.el, as suggested by Ihor, is a good idea.