Skip to content

Commit d27dccc

Browse files
author
Christopher Doris
committed
documentation
1 parent 9b2f687 commit d27dccc

27 files changed

+1689
-1260
lines changed

docs/src/compat.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ Whenever a Python exception is displayed by Julia, `sys.last_traceback` and frie
1212

1313
A `pandas.DataFrame` can be wrapped in Julia as a [`PyPandasDataFrame`](@ref), providing a `Tables.jl`-compatible interface.
1414

15+
Furthermore, any Python object which can be converted to a `PyTable` (e.g. `pandas.DataFrame` can be converted to `PyPandasDataFrame`) satisfies the Tables.jl interface.
16+
1517
In the other direction, the following functions can be used to convert any `Tables.jl`-compatible table to a Python table.
1618

1719
```@docs
18-
pycolumntable
19-
pyrowtable
20-
pypandasdataframe
20+
pytable
2121
```
2222

2323
## MatPlotLib / PyPlot
2424

2525
```@docs
26-
pyplotshow
26+
pyplot_show
2727
```
2828

29-
If Julia is running an IJulia kernel, `pyplotshow()` is automatically called after executing a cell, so that plots generated in a cell are always shown (similar to IPython). It can be disabled by setting `PythonCall.CONFIG.pyplotautoshow = false`.
29+
If Julia is running an IJulia kernel, `pyplot_show()` is automatically called after executing a cell, so that plots generated in a cell are always shown (similar to IPython). It can be disabled by setting `PythonCall.CONFIG.auto_pyplot_show = false`.
3030

3131
## GUIs (including MatPlotLib)
3232

@@ -39,14 +39,6 @@ PythonCall.event_loop_on
3939
PythonCall.event_loop_off
4040
```
4141

42-
### Interaction
43-
44-
The following is an alternative to using event loops to enable interactive plotting.
45-
46-
```@docs
47-
pyinteract
48-
```
49-
5042
### Qt path fix
5143

5244
```@docs
@@ -58,3 +50,5 @@ PythonCall.fix_qt_plugin_path
5850
If Python is running an IPython kernel, then:
5951
- Julia's `Base.stdout` is set to Python's `sys.stdout`.
6052
- An `IPythonDisplay` is pushed onto Julia's display stack, so that `display(x)` goes to IPython if possible.
53+
54+
This is disabled by setting `PythonCall.CONFIG.auto_ipython_display = false`.

docs/src/getting-started.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# Getting Started
22

3-
## You will need
4-
5-
* Julia 1.0 or higher — download [here](https://julialang.org/downloads).
6-
* Python 3.5 or higher — download [here](https://www.python.org/downloads) or set `JULIA_PYTHONCALL_EXE=CONDA` (see below).
7-
83
## Install the Julia package `PythonCall`
94

105
```julia
11-
using Pkg
12-
pkg"add PythonCall"
6+
julia> using Pkg
7+
8+
pkg> add PythonCall
139
```
1410

1511
## Install the Python package `juliacall` (optional)
@@ -36,19 +32,8 @@ packages can always `import juliacall`.
3632

3733
## Environment variables
3834

39-
If Julia and Python are in your PATH, then no further set-up is required.
40-
Otherwise, the following environment variables control how the package finds these.
41-
- `JULIA_PYTHONCALL_EXE`: Path to the Python executable. Or one of the following special
42-
values:
43-
- `CONDA`: Use Python from the default conda environment. In this case, if `conda` is not
44-
detected then `Conda.jl` will automatically install
45-
[`miniconda`](https://docs.conda.io/en/latest/miniconda.html) in your Julia depot.
46-
- `CONDA:{env}`: Use Python from the given conda environment. Also automatically installs
47-
miniconda.
48-
- `PYCALL`: Import [`PyCall`](https://github.com/JuliaPy/PyCall.jl) and use whichever
49-
Python that uses.
50-
- `JULIA_PYTHONCALL_LIB`: Path to the Python library. Normally this is inferred from the Python
51-
executable, but can be over-ridden.
52-
- `PYTHON_JULIACALL_EXE`: Path to the Julia executable.
53-
- `PYTHON_JULIACALL_LIB`: Path to the Julia library. Normally this is inferred from the Julia
54-
executable, but can be over-ridden.
35+
- `JULIA_PYTHONCALL_EXE`: By default, `PythonCall` manages its own installation of Python
36+
specific to a particular Julia environment, so that the set of installed Python packages
37+
is isolated between environments. To instead use a pre-installed version of Python, set
38+
this variable to its path. It can simply be set to `python` if it is in your `PATH`.
39+
- `PYTHON_JULIACALL_EXE`: The path to the Julia executable. By default, it uses `julia`.

docs/src/juliacall.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ There is also a [`RawValue`](#juliacall.RawValue) object, which gives a stricter
3939
- [`DictValue`](#juliacall.DictValue)
4040
- [`SetValue`](#juliacall.SetValue)
4141
- [`IOValue`](#juliacall.IOValue)
42-
- `RawIOValue`
43-
- `BufferedIOValue`
42+
- `BinaryIOValue`
4443
- `TextIOValue`
4544
- [`ModuleValue`](#juliacall.ModuleValue)
4645
- [`TypeValue`](#juliacall.TypeValue)
@@ -105,12 +104,7 @@ juliacall.IOValue - Class
105104
106105
This wraps any Julia `IO` value. It is a subclass of `io.IOBase` and behaves like Python files.
107106
108-
There are also subtypes `RawIOValue`, `BufferedIOValue` and `TextIOValue`, which are subclasses of `io.RawIOBase` (unbuffered bytes), `io.BufferedIOBase` (buffered bytes) and `io.TextIOBase` (text).
109-
110-
###### Members
111-
- `torawio()`: Convert to a `RawIOValue`, an un-buffered bytes file-like object. (See also [`pyrawio`](@ref).)
112-
- `tobufferedio()`: Convert to a `BufferedIOValue`, an buffered bytes file-like object. Julia `IO` objects are converted to this by default. (See also [`pybufferedio`](@ref).)
113-
- `totextio()`: Convert to a `TextIOValue`, a text file-like object. (See also [`pytextio`](@ref).)
107+
There are also subtypes `BinaryIOValue` and `TextIOValue`, which are subclasses of `io.BufferedIOBase` (buffered bytes) and `io.TextIOBase` (text).
114108
`````
115109

116110
`````@customdoc

docs/src/pythoncall.md

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
# The Julia module `PythonCall`
22

3-
To get started, just do `using PythonCall`. There are two main ways to use this module:
4-
5-
**Way 1:** There is a [collection of macros](#Execute-Python-code) for directly executing Python code, interpolating Julia values in and extracting Julia values out. For example ```@pyv `$x+1`::Int``` adds `x` to `1` in Python and converts the result to an `Int`.
6-
7-
**Way 2:** There is a [collection of functions](#Python-functions) which typically produce and consume Python objects. The previous example can be implemented as `pyadd(Int, x, 1)` or `pyconvert(Int, PyObject(x)+1)`.
8-
9-
In all cases, when a Julia value needs to be passed to Python, it will be converted according to [this table](@ref jl2py).
10-
11-
When a Python value is returned to Julia, by default it will be as a [`PyObject`](@ref). Most functions provide an optional way to specify the return type, in which case it will be converted according to [this table](@ref py2jl).
12-
13-
You can also specify one of the [wrapper types](@ref python-wrappers) as a return type.
14-
15-
## `PyObject`
3+
## `Py`
164

175
```@docs
18-
PyObject
6+
Py
197
```
208

21-
## Execute Python code
9+
The object `pybuiltins` has all the standard Python builtin objects as its properties.
10+
Hence you can access `pybuiltins.None` and `pybuiltins.TypeError`.
2211

23-
These macros are used to execute or evaluate Python code. The main differences between them are in whether/how any values are extracted out again.
24-
25-
**Note to package writers.** These all expect there to be a variable `pyglobals` in scope, which is a Python dictionary giving the global scope. For convenience, this module exports such a variable so that these macros work in the REPL. However other packages should define their own global scope by defining `const pyglobals = PyDict()`.
12+
## `@py`
2613

2714
```@docs
2815
@py
29-
@pyv
30-
@pyg
31-
@pya
32-
@pyr
3316
```
3417

3518
## Python functions
3619

20+
Most of the functions in this section are essentially Python builtins with a `py` prefix.
21+
For example `pyint(x)` converts `x` to a Python `int` and is equivalent to `int(x)` in
22+
Python when `x` is a Python object.
23+
24+
Notable exceptions are:
25+
- [`pyconvert`](@ref) to convert a Python object to a Julia object.
26+
- [`pyimport`](@ref) to import a Python module.
27+
- [`pyjl`](@ref) to directly wrap a Julia object as a Python object.
28+
- [`pyclass`](@ref) to construct a new class.
29+
- [`pywith`](@ref) to emulate the Python `with` statement.
30+
3731
### Construct Python objects
3832

3933
These functions convert Julia values into Python objects of standard types.
4034

4135
```@docs
42-
pynone
4336
pybool
4437
pyint
4538
pyfloat
39+
pycomplex
4640
pystr
4741
pybytes
4842
pytuple
@@ -53,10 +47,10 @@ pyset
5347
pyfrozenset
5448
pydict
5549
pyslice
56-
pyellipsis
57-
pynotimplemented
50+
pyrange
5851
pymethod
5952
pytype
53+
pyclass
6054
```
6155

6256
### Wrap Julia values
@@ -67,23 +61,26 @@ These functions wrap Julia values into Python objects, documented [here](@ref ju
6761
pyjl
6862
pyjlraw
6963
pyisjl
70-
pyjlgetvalue
64+
pyjlvalue
7165
pytextio
72-
pyrawio
73-
pybufferedio
66+
pybinaryio
7467
```
7568

7669
### Python builtins
7770

7871
```@docs
7972
pyconvert
73+
@pyconvert
8074
pyimport
75+
pyimport_conda
8176
pywith
8277
pyis
8378
pyrepr
79+
pyascii
8480
pyhasattr
8581
pygetattr
8682
pysetattr
83+
pydelattr
8784
pydir
8885
pycall
8986
pylen
@@ -99,46 +96,51 @@ pyhash
9996
pyiter
10097
```
10198

102-
### Numbers
99+
### Numeric functions
103100

104101
```@docs
105-
pyeq
106-
pyne
107-
pyle
108-
pylt
109-
pyge
110-
pygt
102+
pyneg
103+
pypos
104+
pyabs
105+
pyinv
111106
pyadd
112-
pyiadd
113107
pysub
114-
pyisub
115108
pymul
116-
pyimul
117109
pymatmul
118-
pyimatmul
110+
pypow
119111
pyfloordiv
120-
pyifloordiv
121112
pytruediv
122-
pyitruediv
123113
pymod
124-
pyimod
125114
pydivmod
126115
pylshift
127-
pyilshift
128116
pyrshift
129-
pyirshift
130117
pyand
131-
pyiand
132-
pyor
133-
pyior
134118
pyxor
135-
pyixor
136-
pypow
119+
pyor
120+
pyiadd
121+
pyisub
122+
pyimul
123+
pyimatmul
137124
pyipow
138-
pyneg
139-
pypos
140-
pyabs
141-
pyinv
125+
pyifloordiv
126+
pyitruediv
127+
pyimod
128+
pyilshift
129+
pyirshift
130+
pyiand
131+
pyixor
132+
pyior
133+
```
134+
135+
### Comparisons
136+
137+
```@docs
138+
pyeq
139+
pyne
140+
pyle
141+
pylt
142+
pyge
143+
pygt
142144
```
143145

144146
## [Wrapper types](@id python-wrappers)
@@ -149,13 +151,8 @@ PySet
149151
PyDict
150152
PyIterable
151153
PyArray
152-
PyBuffer
153154
PyIO
155+
PyTable
154156
PyPandasDataFrame
155-
PyCode
156-
@py_cmd
157-
@pyv_cmd
158-
PyInternedString
159-
@pystr_str
160-
PyException
157+
PyObjectArray
161158
```

src/abstract/iter.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
pyiter(x)
3+
4+
Equivalent to `iter(x)` in Python.
5+
"""
16
pyiter(x) = pynew(errcheck(@autopy x C.PyObject_GetIter(getptr(x_))))
27
export pyiter
38

0 commit comments

Comments
 (0)