Skip to content

Commit

Permalink
Add coverage output to pytest output (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj committed Nov 25, 2021
1 parent afa250b commit 4b24195
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
- name: Run tests
run: |
export RUSTFLAGS="-C debuginfo=0"
cd py-polars && rustup override set nightly-2021-10-21 && make build-and-test
cd py-polars && rustup override set nightly-2021-10-21 && make build-and-test-with-cov
cargo clippy
# test if we can import polars without any requirements
- name: Import polars
Expand Down
7 changes: 7 additions & 0 deletions py-polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ test:
maturin develop
pytest tests

test-with-cov:
maturin develop
cd tests && pytest --cov=polars --import-mode=importlib

test-build:
maturin build -o wheels

test-install: test-build pip

build-and-test: test-install
pytest tests

build-and-test-with-cov: test-install
cd tests && pytest --cov=polars --import-mode=importlib
3 changes: 2 additions & 1 deletion py-polars/build.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pandas

# Tooling
maturin==0.11.0
pytest==5.3.1
pytest==6.2.5
pytest-cov[toml]==3.0.0
black==21.6b0
isort~=5.9.2
mypy==0.910
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

try:
from polars.polars import version
except ImportError as e:
except ImportError as e: # pragma: no cover

def version() -> str:
return ""
Expand Down
10 changes: 6 additions & 4 deletions py-polars/polars/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from polars.internals import DataFrame, Series

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
import pandas as pd
import pyarrow as pa

Expand All @@ -14,7 +14,7 @@
import pyarrow as pa

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False


Expand Down Expand Up @@ -192,7 +192,9 @@ def from_arrow(
]
"""
if not _PYARROW_AVAILABLE:
raise ImportError("'pyarrow' is required when using from_arrow().")
raise ImportError(
"'pyarrow' is required when using from_arrow()."
) # pragma: no cover
if isinstance(a, pa.Table):
return DataFrame._from_arrow(a, rechunk=rechunk)
elif isinstance(a, (pa.Array, pa.ChunkedArray)):
Expand Down Expand Up @@ -257,7 +259,7 @@ def from_pandas(
"""
try:
import pandas as pd
except ImportError as e:
except ImportError as e: # pragma: no cover
raise ImportError("'pandas' is required when using from_pandas().") from e

if isinstance(df, (pd.Series, pd.DatetimeIndex)):
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pyarrow as pa

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False

from _ctypes import _SimpleCData
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/datatypes_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from polars.polars import PySeries

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True


Expand Down
16 changes: 8 additions & 8 deletions py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
import pandas as pd
import pyarrow as pa

Expand All @@ -36,7 +36,7 @@
import pyarrow as pa

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False

################################
Expand Down Expand Up @@ -119,7 +119,7 @@ def sequence_to_pyseries(
dtype_ = type(value) if value is not None else float

if dtype_ == date or dtype_ == datetime:
if not _PYARROW_AVAILABLE:
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required for converting a Sequence of date or datetime values to a PySeries."
)
Expand All @@ -129,7 +129,7 @@ def sequence_to_pyseries(
nested_value = _get_first_non_none(value)
nested_dtype = type(nested_value) if value is not None else float

if not _PYARROW_AVAILABLE:
if not _PYARROW_AVAILABLE: # pragma: no cover
dtype = py_type_to_dtype(nested_dtype)
return PySeries.new_list(name, values, dtype)

Expand Down Expand Up @@ -201,7 +201,7 @@ def pandas_to_pyseries(
"""
Construct a PySeries from a pandas Series or DatetimeIndex.
"""
if not _PYARROW_AVAILABLE:
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required when constructing a PySeries from a pandas Series."
)
Expand Down Expand Up @@ -352,7 +352,7 @@ def arrow_to_pydf(
"""
Construct a PyDataFrame from an Arrow Table.
"""
if not _PYARROW_AVAILABLE:
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required when constructing a PyDataFrame from an Arrow Table."
)
Expand Down Expand Up @@ -403,7 +403,7 @@ def pandas_to_pydf(
"""
Construct a PyDataFrame from a pandas DataFrame.
"""
if not _PYARROW_AVAILABLE:
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required when constructing a PyDataFrame from a pandas DataFrame."
)
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from polars.polars import PyExpr

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

from polars import internals as pli
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import pyarrow.parquet

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False

from polars import internals as pli
Expand All @@ -46,7 +46,7 @@
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

from polars._html import NotebookFormatter
Expand All @@ -64,7 +64,7 @@
import pandas as pd

_PANDAS_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PANDAS_AVAILABLE = False


Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from polars.polars import py_diag_concat_df as _diag_concat_df

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True


Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from polars.polars import PyExpr, PyLazyFrame, PyLazyGroupBy

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

from polars import internals as pli
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/lazy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from polars.polars import spearman_rank_corr as pyspearman_rank_corr

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True


Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pyarrow as pa

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False

from polars import internals as pli
Expand All @@ -25,7 +25,7 @@
from polars.polars import PyDataFrame, PySeries

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

from polars.datatypes import (
Expand Down Expand Up @@ -59,7 +59,7 @@
import pandas as pd

_PANDAS_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PANDAS_AVAILABLE = False


Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/whenthen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from polars.polars import when as pywhen

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True

from polars import internals as pli
Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import pyarrow.parquet

_PYARROW_AVAILABLE = True
except ImportError:
except ImportError: # pragma: no cover
_PYARROW_AVAILABLE = False

from polars.convert import from_arrow
Expand All @@ -33,7 +33,7 @@

try:
from polars.polars import ipc_schema as _ipc_schema
except ImportError:
except ImportError: # pragma: no cover
pass

try:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/string_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from polars.polars import toggle_string_cache as pytoggle_string_cache

_DOCUMENTING = False
except ImportError:
except ImportError: # pragma: no cover
_DOCUMENTING = True


Expand Down
3 changes: 3 additions & 0 deletions py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ profile = "black"
ignore_missing_imports = true
disallow_untyped_defs = true
files = ["polars", "tests"]

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "@overload", "@tp.overload"]

0 comments on commit 4b24195

Please sign in to comment.