emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* indentation error in python source block
@ 2018-11-09  3:51 Seb
  2018-11-10  7:30 ` Nicolas Goaziou
  2018-12-14 14:12 ` iemacs
  0 siblings, 2 replies; 4+ messages in thread
From: Seb @ 2018-11-09  3:51 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I believe I've hit a strange bug.  Given this file:

---<--------------------cut here---------------start------------------->---
#+STARTUP: content indent hideblocks
#+PROPERTY: header-args :tangle yes
#+PROPERTY: header-args:python :session *Python*

#+NAME: python_init
#+BEGIN_SRC python :results silent :exports none
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#+END_SRC

#+NAME: test
#+BEGIN_SRC python :results file :exports results
beg = ["2017-07-13 15:27:31", "2017-07-13 15:28:24"]
beg = pd.to_datetime(beg)
end = ["2017-07-13 15:28:03", "2017-07-13 15:28:57"]
end = pd.to_datetime(end)
pos = np.arange(1, 3).tolist()
experiment = pd.DataFrame(dict(index=np.arange(1, 3),
                               beg=beg, end=end, pos=pos))
# Mid points
experiment["mid"] = (experiment["beg"] +
                     (experiment["end"] - experiment["beg"]) / 2)
fig, axs = plt.subplots(3, 1, sharex=True)
# Shade experiment periods
for idx, row in experiment.iterrows():
    for ax in axs:
        ax.axvspan(row["beg"], row["end"], facecolor="0.5")
    axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
                    xycoords=("data", "axes fraction"))
# TEMPORARY: limit to experiment periods
axs[0].set_xlim(experiment["beg"].iloc[0],
                experiment["end"].iloc[-1])
fig.tight_layout()
fig.savefig("junk.png", bbox_inches="tight")
plt.close()
"junk.png"
#+END_SRC
---<--------------------cut here---------------end--------------------->---

Problem is in the second source block.  With point on the #+BEGIN line,
hitting C-c to execute the block yields indentation errors in the
Python process (first one):

---<--------------------cut here---------------start------------------->---
>>>                 experiment["end"].iloc[-1])
  File "<stdin>", line 1
    axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
    ^
IndentationError: unexpected indent
---<--------------------cut here---------------end--------------------->---

Tangling the file and running the Python script shows no error at all.
Executing the source block from the dedicated buffer via C-c '
(`org-edit-special') also runs without errors.  What is going on?

Thanks,
-- 
Seb

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: indentation error in python source block
  2018-11-09  3:51 indentation error in python source block Seb
@ 2018-11-10  7:30 ` Nicolas Goaziou
  2018-11-10 15:58   ` Sebastian P. Luque
  2018-12-14 14:12 ` iemacs
  1 sibling, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2018-11-10  7:30 UTC (permalink / raw)
  To: Seb; +Cc: emacs-orgmode

Hello,

Seb <spluque@gmail.com> writes:

> I believe I've hit a strange bug. Given this file:
>
> ---<--------------------cut here---------------start------------------->---
> #+STARTUP: content indent hideblocks
> #+PROPERTY: header-args :tangle yes
> #+PROPERTY: header-args:python :session *Python*
>
> #+NAME: python_init
> #+BEGIN_SRC python :results silent :exports none
> import matplotlib as mpl
> mpl.use("Agg")
> import matplotlib.pyplot as plt
> import numpy as np
> import pandas as pd
> #+END_SRC
>
> #+NAME: test
> #+BEGIN_SRC python :results file :exports results
> beg = ["2017-07-13 15:27:31", "2017-07-13 15:28:24"]
> beg = pd.to_datetime(beg)
> end = ["2017-07-13 15:28:03", "2017-07-13 15:28:57"]
> end = pd.to_datetime(end)
> pos = np.arange(1, 3).tolist()
> experiment = pd.DataFrame(dict(index=np.arange(1, 3),
>                                beg=beg, end=end, pos=pos))
> # Mid points
> experiment["mid"] = (experiment["beg"] +
>                      (experiment["end"] - experiment["beg"]) / 2)
> fig, axs = plt.subplots(3, 1, sharex=True)
> # Shade experiment periods
> for idx, row in experiment.iterrows():
>     for ax in axs:
>         ax.axvspan(row["beg"], row["end"], facecolor="0.5")
>     axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
>                     xycoords=("data", "axes fraction"))
> # TEMPORARY: limit to experiment periods
> axs[0].set_xlim(experiment["beg"].iloc[0],
>                 experiment["end"].iloc[-1])
> fig.tight_layout()
> fig.savefig("junk.png", bbox_inches="tight")
> plt.close()
> "junk.png"
> #+END_SRC
> ---<--------------------cut here---------------end--------------------->---
>
>
> Problem is in the second source block.  With point on the #+BEGIN line,
> hitting C-c to execute the block yields indentation errors in the
> Python process (first one):
>
> ---<--------------------cut here---------------start------------------->---
>>>>                 experiment["end"].iloc[-1])
>   File "<stdin>", line 1
>     axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
>     ^
> IndentationError: unexpected indent
> ---<--------------------cut here---------------end--------------------->---

I cannot reproduce your error. You may want to upgrade Org.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: indentation error in python source block
  2018-11-10  7:30 ` Nicolas Goaziou
@ 2018-11-10 15:58   ` Sebastian P. Luque
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian P. Luque @ 2018-11-10 15:58 UTC (permalink / raw)
  To: emacs-orgmode

On Sat, 10 Nov 2018 08:30:50 +0100,
Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

[...]

> I cannot reproduce your error. You may want to upgrade Org.

I'm already using the latest Org from Elpa (9.1.14), and get the error
with:

$ emacs -q -l emacs_pkg_init.el

╭───── [ emacs_pkg_init.el ]
│ (setq package-archives
│    (quote
│     (("gnu" . "http://elpa.gnu.org/packages/")
│      ("melpa" . "http://melpa.org/packages/")
│      ("marmalade" . "https://marmalade-repo.org/packages/")
│      ("org" . "http://orgmode.org/elpa/"))))
│ (package-initialize)
│ (org-babel-do-load-languages
│  'org-babel-load-languages
│  '((python . t)))
╰─────

-- 
Seb

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: indentation error in python source block
  2018-11-09  3:51 indentation error in python source block Seb
  2018-11-10  7:30 ` Nicolas Goaziou
@ 2018-12-14 14:12 ` iemacs
  1 sibling, 0 replies; 4+ messages in thread
From: iemacs @ 2018-12-14 14:12 UTC (permalink / raw)
  To: Seb; +Cc: org-mode mailing list

On Fri, Nov 9, 2018 at 11:52 AM Seb <spluque@gmail.com> wrote:
>
> Hello,
>
> I believe I've hit a strange bug.  Given this file:
>
> ---<--------------------cut here---------------start------------------->---
> #+STARTUP: content indent hideblocks
> #+PROPERTY: header-args :tangle yes
> #+PROPERTY: header-args:python :session *Python*
>
> #+NAME: python_init
> #+BEGIN_SRC python :results silent :exports none
> import matplotlib as mpl
> mpl.use("Agg")
> import matplotlib.pyplot as plt
> import numpy as np
> import pandas as pd
> #+END_SRC
>
> #+NAME: test
> #+BEGIN_SRC python :results file :exports results
> beg = ["2017-07-13 15:27:31", "2017-07-13 15:28:24"]
> beg = pd.to_datetime(beg)
> end = ["2017-07-13 15:28:03", "2017-07-13 15:28:57"]
> end = pd.to_datetime(end)
> pos = np.arange(1, 3).tolist()
> experiment = pd.DataFrame(dict(index=np.arange(1, 3),
>                                beg=beg, end=end, pos=pos))
> # Mid points
> experiment["mid"] = (experiment["beg"] +
>                      (experiment["end"] - experiment["beg"]) / 2)
> fig, axs = plt.subplots(3, 1, sharex=True)
> # Shade experiment periods
> for idx, row in experiment.iterrows():
>     for ax in axs:
>         ax.axvspan(row["beg"], row["end"], facecolor="0.5")

How about adding an empty line here?

>     axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
>                     xycoords=("data", "axes fraction"))
> # TEMPORARY: limit to experiment periods
> axs[0].set_xlim(experiment["beg"].iloc[0],
>                 experiment["end"].iloc[-1])
> fig.tight_layout()
> fig.savefig("junk.png", bbox_inches="tight")
> plt.close()
> "junk.png"
> #+END_SRC
> ---<--------------------cut here---------------end--------------------->---
>
> Problem is in the second source block.  With point on the #+BEGIN line,
> hitting C-c to execute the block yields indentation errors in the
> Python process (first one):
>
> ---<--------------------cut here---------------start------------------->---
> >>>                 experiment["end"].iloc[-1])
>   File "<stdin>", line 1
>     axs[0].annotate(row["pos"], (row["mid"], 1), ha="center",
>     ^
> IndentationError: unexpected indent
> ---<--------------------cut here---------------end--------------------->---
>
> Tangling the file and running the Python script shows no error at all.
> Executing the source block from the dedicated buffer via C-c '
> (`org-edit-special') also runs without errors.  What is going on?
>
> Thanks,
> --
> Seb
>
>


-- 


Yours faithfully,

Tian Qiu

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-14 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09  3:51 indentation error in python source block Seb
2018-11-10  7:30 ` Nicolas Goaziou
2018-11-10 15:58   ` Sebastian P. Luque
2018-12-14 14:12 ` iemacs

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).