Skip to content

Commit

Permalink
Activate mirror tests on pandoc format
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 27, 2019
1 parent e343610 commit 9efb67e
Show file tree
Hide file tree
Showing 19 changed files with 1,116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
::: {.cell .code execution_count="1"}
``` {.python}
1 + 1
```

::: {.output .execute_result execution_count="1"}
2
:::
:::

::: {.cell .markdown}
A markdown cell And below, the cell for function f has non trivial cell
metadata. And the next cell as well.
:::

::: {.cell .code execution_count="2" attributes="{"n":"10","id":"","classes":[]}"}
``` {.python}
def f(x):
return x
```
:::

::: {.cell .code execution_count="3" attributes="{"n":"10","id":"","classes":[]}"}
``` {.python}
f(5)
```

::: {.output .execute_result execution_count="3"}
5
:::
:::

::: {.cell .markdown}
More text
:::

::: {.cell .code execution_count="4"}
``` {.python}
2 + 2
```

::: {.output .execute_result execution_count="4"}
4
:::
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
::: {.cell .code execution_count="1"}
``` {.python}
%%html
<p><a href="https://github.com/mwouts/jupytext", style="color: rgb(0,0,255)">Jupytext</a> on GitHub</p>
```

::: {.output .display_data}
<p><a href="https://github.com/mwouts/jupytext", style="color: rgb(0,0,255)">Jupytext</a> on GitHub</p>
:::
:::

::: {.cell .code execution_count="2"}
``` {.python}
%%latex
$\frac{\pi}{2}$
```

::: {.output .display_data}
$\frac{\pi}{2}$
:::
:::

::: {.cell .code execution_count="3"}
``` {.python}
%load_ext rpy2.ipython
```
:::

::: {.cell .code execution_count="4"}
``` {.python}
%%R
library(ggplot2)
ggplot(data=data.frame(x=c('A', 'B'), y=c(5, 2)), aes(x,weight=y)) + geom_bar()
```

::: {.output .display_data}
![](7f97cecde4f72e650de2f3937ac4999467e76306.png)
:::
:::

::: {.cell .code execution_count="5"}
``` {.python}
%matplotlib inline
import pandas as pd
pd.Series({'A':5, 'B':2}).plot(figsize=(3,2), kind='bar')
```

::: {.output .execute_result execution_count="5"}
<matplotlib.axes._subplots.AxesSubplot at 0x2da0c41a9e8>
:::

::: {.output .display_data}
![](9344ac2b35133877848c9a89b2fbbcc3dcce81e0.png)
:::
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
::: {.cell .markdown}
##################################################################

This is a notebook that contains many hash signs. Hopefully its python
representation is not recognized as a Sphinx Gallery script\...

##################################################################
:::

::: {.cell .code execution_count="1"}
``` {.python}
some = 1
code = 2
some+code
##################################################################
# A comment
##################################################################
# Another comment
```

::: {.output .execute_result execution_count="1"}
3
:::
:::

::: {.cell .markdown}
################################################################## {#section}

This is a notebook that contains many hash signs. Hopefully its python
representation is not recognized as a Sphinx Gallery script\...

################################################################## {#section-1}
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
::: {.cell .markdown}
Part one - various cells
========================
:::

::: {.cell .markdown}
Here we have a markdown cell

with two blank lines
:::

::: {.cell .markdown}
Now we have a markdown cell with a code block inside it

``` {.python}
1 + 1
```

After that cell we\'ll have a code cell
:::

::: {.cell .code execution_count="1"}
``` {.python}
2 + 2
3 + 3
```

::: {.output .execute_result execution_count="1"}
6
:::
:::

::: {.cell .markdown}
Followed by a raw cell
:::

::: {.cell .raw}
```{=}
This is
the content
of the raw cell
```
:::

::: {.cell .markdown}
Part two - cell metadata
========================
:::

::: {.cell .markdown key="value"}
This is a markdown cell with cell metadata `{"key": "value"}`
:::

::: {.cell .code execution_count="2" .class="null" tags="["parameters"]"}
``` {.python}
"""This is a code cell with metadata `{"tags":["parameters"], ".class":null}`"""
```

::: {.output .execute_result execution_count="2"}
'This is a code cell with metadata `{"tags":["parameters"], ".class":null}`'
:::
:::

::: {.cell .raw key="value"}
```{=}
This is a raw cell with cell metadata `{"key": "value"}`
```
:::
46 changes: 46 additions & 0 deletions tests/notebooks/mirror/ipynb_to_pandoc/Notebook_with_R_magic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
::: {.cell .markdown}
A notebook with R cells
=======================

This notebook shows the use of R cells to generate plots
:::

::: {.cell .code execution_count="1"}
``` {.python}
%load_ext rpy2.ipython
```
:::

::: {.cell .code execution_count="2"}
``` {.python}
%%R
suppressMessages(require(tidyverse))
```
:::

::: {.cell .code execution_count="3"}
``` {.python}
%%R
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point()
```

::: {.output .display_data}
![](3fc4493185b3637a4127483394ece754faff16c7.png)
:::
:::

::: {.cell .markdown}
The default plot dimensions are not good for us, so we use the -w and -h
parameters in %%R magic to set the plot size
:::

::: {.cell .code execution_count="4"}
``` {.python}
%%R -w 400 -h 240
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point()
```

::: {.output .display_data}
![](92a00f6aa6af61f269e4b4a9db7fe31d5f8b1dbb.png)
:::
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
::: {.cell .code execution_count="1"}
``` {.python}
%load_ext rpy2.ipython
import pandas as pd
df = pd.DataFrame(
{
"Letter": ["a", "a", "a", "b", "b", "b", "c", "c", "c"],
"X": [4, 3, 5, 2, 1, 7, 7, 5, 9],
"Y": [0, 4, 3, 6, 7, 10, 11, 9, 13],
"Z": [1, 2, 3, 1, 2, 3, 1, 2, 3],
}
)
```
:::

::: {.cell .code execution_count="2"}
``` {.python}
%%R -i df
library("ggplot2")
ggplot(data = df) + geom_point(aes(x = X, y = Y, color = Letter, size = Z))
```

::: {.output .stream .stderr}
C:\Users\Marco\AppData\Local\conda\conda\envs\python3\lib\site-packages\rpy2-2.9.4-py3.6-win-amd64.egg\rpy2\robjects\pandas2ri.py:191: FutureWarning: from_items is deprecated. Please use DataFrame.from_dict(dict(items), ...) instead. DataFrame.from_dict(OrderedDict(items)) may be used to preserve the key order.
res = PandasDataFrame.from_items(items)
:::

::: {.output .display_data}
![](7d03ea06cc5a2be89de49cf90faff680e9b93dfa.png)
:::
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
::: {.cell .code execution_count="1" scrolled="false"}
``` {.python}
%%time
print('asdf')
```

::: {.output .stream .stdout}
asdf
CPU times: user 132 µs, sys: 57 µs, total: 189 µs
Wall time: 188 µs
:::
:::

::: {.cell .markdown}
Thanks for jupytext!
:::

::: {.cell .code collapsed="true"}
``` {.python}
```
:::
17 changes: 17 additions & 0 deletions tests/notebooks/mirror/ipynb_to_pandoc/frozen_cell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
::: {.cell .code execution_count="1" ExecuteTime="{"start_time":"2018-10-17T10:31:56.157308Z","end_time":"2018-10-17T10:31:56.160823Z"}"}
``` {.python}
# This is an unfrozen cell. Works as usual.
print("I'm a regular cell so I run and print!")
```

::: {.output .stream .stdout}
I'm a regular cell so I run and print!
:::
:::

::: {.cell .code deletable="false" editable="false" run_control="{"frozen":true}"}
``` {.python}
# This is an frozen cell
print("I'm frozen so Im not executed :(")
```
:::
28 changes: 28 additions & 0 deletions tests/notebooks/mirror/ipynb_to_pandoc/ir_notebook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
::: {.cell .markdown}
This is a jupyter notebook that uses the IR kernel.
:::

::: {.cell .code execution_count="8"}
``` {.R}
sum(1:10)
```

::: {.output .display_data}
55
:::
:::

::: {.cell .code execution_count="9"}
``` {.R}
plot(cars)
```

::: {.output .display_data}
![](6816e48e6ab4ff95b3497067ec010f529f3ae4c5.png)
:::
:::

::: {.cell .code}
``` {.R}
```
:::
Loading

0 comments on commit 9efb67e

Please sign in to comment.