Skip to content

Commit

Permalink
python docs, do not compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 5, 2021
1 parent 231bab5 commit 79faf9d
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 68 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r py-polars/build.requirements.txt
cd py-polars && ./tasks.sh test-install
- name: Build python reference
run: |
cd py-polars/docs
Expand Down
7 changes: 4 additions & 3 deletions py-polars/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys

# add polars directory
sys.path.insert(0, os.path.abspath("../.."))

# -- Project information -----------------------------------------------------

Expand Down
6 changes: 5 additions & 1 deletion py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# flake8: noqa
import warnings

try:
from polars.polars import version
except ImportError as e:
raise ImportError("Polars binary files missing!") from e
version = lambda: ""
# this is only useful for documentation
warnings.warn("polars binary missing!")

# mypy needs these imported explicitly
from polars.eager.frame import DataFrame, wrap_df
Expand Down
97 changes: 53 additions & 44 deletions py-polars/polars/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import pyarrow as pa
from _ctypes import _SimpleCData

from polars.polars import PySeries
try:
from polars.polars import PySeries

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

__all__ = [
"DataType",
Expand Down Expand Up @@ -258,23 +263,24 @@ def pytype_to_polars_type(data_type: Type[Any]) -> Type[DataType]:
return polars_type


_POLARS_TYPE_TO_CONSTRUCTOR = {
Float32: PySeries.new_opt_f32,
Float64: PySeries.new_opt_f64,
Int8: PySeries.new_opt_i8,
Int16: PySeries.new_opt_i16,
Int32: PySeries.new_opt_i32,
Int64: PySeries.new_opt_i64,
UInt8: PySeries.new_opt_u8,
UInt16: PySeries.new_opt_u16,
UInt32: PySeries.new_opt_u32,
UInt64: PySeries.new_opt_u64,
Date32: PySeries.new_opt_i32,
Date64: PySeries.new_opt_i32,
Boolean: PySeries.new_opt_bool,
Utf8: PySeries.new_str,
Object: PySeries.new_object,
}
if not _DOCUMENTING:
_POLARS_TYPE_TO_CONSTRUCTOR = {
Float32: PySeries.new_opt_f32,
Float64: PySeries.new_opt_f64,
Int8: PySeries.new_opt_i8,
Int16: PySeries.new_opt_i16,
Int32: PySeries.new_opt_i32,
Int64: PySeries.new_opt_i64,
UInt8: PySeries.new_opt_u8,
UInt16: PySeries.new_opt_u16,
UInt32: PySeries.new_opt_u32,
UInt64: PySeries.new_opt_u64,
Date32: PySeries.new_opt_i32,
Date64: PySeries.new_opt_i32,
Boolean: PySeries.new_opt_bool,
Utf8: PySeries.new_str,
Object: PySeries.new_object,
}


def polars_type_to_constructor(
Expand All @@ -289,20 +295,21 @@ def polars_type_to_constructor(
raise ValueError(f"Cannot construct PySeries for type {dtype}.")


_NUMPY_TYPE_TO_CONSTRUCTOR = {
np.float32: PySeries.new_f32,
np.float64: PySeries.new_f64,
np.int8: PySeries.new_i8,
np.int16: PySeries.new_i16,
np.int32: PySeries.new_i32,
np.int64: PySeries.new_i64,
np.uint8: PySeries.new_u8,
np.uint16: PySeries.new_u16,
np.uint32: PySeries.new_u32,
np.uint64: PySeries.new_u64,
np.str_: PySeries.new_str,
bool: PySeries.new_bool,
}
if not _DOCUMENTING:
_NUMPY_TYPE_TO_CONSTRUCTOR = {
np.float32: PySeries.new_f32,
np.float64: PySeries.new_f64,
np.int8: PySeries.new_i8,
np.int16: PySeries.new_i16,
np.int32: PySeries.new_i32,
np.int64: PySeries.new_i64,
np.uint8: PySeries.new_u8,
np.uint16: PySeries.new_u16,
np.uint32: PySeries.new_u32,
np.uint64: PySeries.new_u64,
np.str_: PySeries.new_str,
bool: PySeries.new_bool,
}


def numpy_type_to_constructor(dtype: Type[np.dtype]) -> Callable[..., "PySeries"]:
Expand All @@ -315,12 +322,13 @@ def numpy_type_to_constructor(dtype: Type[np.dtype]) -> Callable[..., "PySeries"
return PySeries.new_object


_PY_TYPE_TO_CONSTRUCTOR = {
float: PySeries.new_opt_f64,
int: PySeries.new_opt_i64,
str: PySeries.new_str,
bool: PySeries.new_opt_bool,
}
if not _DOCUMENTING:
_PY_TYPE_TO_CONSTRUCTOR = {
float: PySeries.new_opt_f64,
int: PySeries.new_opt_i64,
str: PySeries.new_str,
bool: PySeries.new_opt_bool,
}


def py_type_to_constructor(dtype: Type[Any]) -> Callable[..., "PySeries"]:
Expand All @@ -333,12 +341,13 @@ def py_type_to_constructor(dtype: Type[Any]) -> Callable[..., "PySeries"]:
return PySeries.new_object


_PY_TYPE_TO_ARROW_TYPE = {
float: pa.float64(),
int: pa.int64(),
str: pa.large_utf8(),
bool: pa.bool_(),
}
if not _DOCUMENTING:
_PY_TYPE_TO_ARROW_TYPE = {
float: pa.float64(),
int: pa.int64(),
str: pa.large_utf8(),
bool: pa.bool_(),
}


def py_type_to_arrow_type(dtype: Type[Any]) -> pa.lib.DataType:
Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/eager/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
sequence_to_pydf,
series_to_pydf,
)
from polars.polars import PyDataFrame, PySeries

try:
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from .._html import NotebookFormatter
from ..datatypes import DTYPES, Boolean, DataType, UInt32, pytype_to_polars_type
Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/eager/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
sequence_to_pyseries,
series_to_pyseries,
)
from polars.polars import PyDataFrame, PySeries

try:
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from ..datatypes import (
DTYPE_TO_FFINAME,
Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
py_type_to_arrow_type,
py_type_to_constructor,
)
from polars.polars import PyDataFrame, PySeries

try:
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True
from polars.utils import coerce_arrow

if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions py-polars/polars/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ def scan_csv(
Start reading after `skip_rows`.
stop_after_n_rows
After n rows are read from the CSV, it stops reading.
During multi-threaded parsing, an upper bound of `n` rows
cannot be guaranteed.
During multi-threaded parsing, an upper bound of `n` rows cannot be guaranteed.
cache
Cache the result after reading.
dtype
Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/lazy/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from typing import Any, Callable, Optional, Sequence, Type, Union

import polars as pl
from polars.polars import PyExpr

try:
from polars.polars import PyExpr

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from ..datatypes import Boolean, DataType, Date32, Date64, Float64, Int64, Utf8
from .functions import UDF, col, lit
Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/lazy/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Type, Union

import polars as pl
from polars.polars import PyExpr, PyLazyFrame, PyLazyGroupBy

try:
from polars.polars import PyExpr, PyLazyFrame, PyLazyGroupBy

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from ..datatypes import DataType, pytype_to_polars_type
from ..utils import _process_null_values
Expand Down
26 changes: 16 additions & 10 deletions py-polars/polars/lazy/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
import numpy as np

import polars as pl
from polars.polars import argsort_by as pyargsort_by
from polars.polars import binary_function as pybinary_function
from polars.polars import col as pycol
from polars.polars import concat_str as _concat_str
from polars.polars import cov as pycov
from polars.polars import except_ as pyexcept
from polars.polars import fold as pyfold
from polars.polars import lit as pylit
from polars.polars import pearson_corr as pypearson_corr
from polars.polars import series_from_range as _series_from_range

try:
from polars.polars import argsort_by as pyargsort_by
from polars.polars import binary_function as pybinary_function
from polars.polars import col as pycol
from polars.polars import concat_str as _concat_str
from polars.polars import cov as pycov
from polars.polars import except_ as pyexcept
from polars.polars import fold as pyfold
from polars.polars import lit as pylit
from polars.polars import pearson_corr as pypearson_corr
from polars.polars import series_from_range as _series_from_range

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from ..datatypes import DataType, Date64, Int64

Expand Down
8 changes: 7 additions & 1 deletion py-polars/polars/lazy/whenthen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from typing import Any, Union

import polars as pl
from polars.polars import when as pywhen

try:
from polars.polars import when as pywhen

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

from .expr import expr_to_lit_or_expr

Expand Down
7 changes: 6 additions & 1 deletion py-polars/polars/string_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from types import TracebackType
from typing import Optional, Type

from polars.polars import toggle_string_cache as pytoggle_string_cache
try:
from polars.polars import toggle_string_cache as pytoggle_string_cache

_DOCUMENTING = False
except ImportError:
_DOCUMENTING = True

__all__ = [
"StringCache",
Expand Down

0 comments on commit 79faf9d

Please sign in to comment.