Jupytext: Wrong cell separation when creating .ipynb from .py

Created on 17 Mar 2020  路  6Comments  路  Source: mwouts/jupytext

Let's say I work in a notebook file, paired to a .py file, and write one function per cell.

When I re-generate the .ipynb notebook from the .py file I have noticed that some functions now live in the same cell.

This is best illustrated by the images below. The following code:
Screenshot 2020-03-17 at 21 43 10

becomes, after regenerating the .ipynb from the paired .py:
Screenshot 2020-03-17 at 21 36 20

The problem does not impact all functions/cells. I've inspected the code in the .py file and cannot find any obvious difference between the impacted cells/functions and the non impacted ones.

I'm using jupytext version 1.4.0 but had noticed this behaviour on previous versions too.

All 6 comments

Hello @jhelie . Thanks for reporting this. Yes that is not expected.... Maybe you could share, or email me privately, a sample notebook that reproduces the issue?

Hi Marc, sure I'll try to send you one over the weekend.

Hi @mwouts, I was trying to create a MWE and found out what my mistake was: one of my docstrings started with """" (4 double quotes instead of 3).

If you want to reproduce just create a .ipynb with these 2 cells:

def fun_1(df):
  """"
  docstring starting with 4 double quotes and ending with 3
  """
  return df
````
and 
```python
def fun_2(df):
  """
  docstring
  """
  return df

So no bug, I'm just surprised that this didn't break the code - it looked and performed as expected - but feel free to close this issue.

Oh, interesting! I'm sure we can improve the string parser to avoid this... let me have a look...

What was happening is that the parser was seeing """ twice in the quadruple quote... You won't have this issue any more in the next release.

Glad to hear this was fixable - thanks for doing so so quickly!

Was this page helpful?
0 / 5 - 0 ratings