Skip to content

Commit

Permalink
Improve coverage report settings (#4039)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jul 17, 2022
1 parent 19cc512 commit 34b8adf
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 72 deletions.
2 changes: 1 addition & 1 deletion py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

try:
import pyarrow as pa

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

try:
import pandas as pd

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

if sys.version_info >= (3, 8):
Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/datatypes.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: # pragma: no cover
except ImportError:
_PYARROW_AVAILABLE = False

from _ctypes import _SimpleCData # type: ignore
Expand All @@ -18,7 +18,7 @@
from polars.polars import dtype_str_repr

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


Expand Down
10 changes: 4 additions & 6 deletions py-polars/polars/datatypes_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
from polars.polars import PySeries

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

try:
import numpy as np

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

if not _DOCUMENTING:
Expand Down Expand Up @@ -101,10 +101,8 @@ def numpy_type_to_constructor(dtype: type[np.dtype]) -> Callable[..., PySeries]:
return _NUMPY_TYPE_TO_CONSTRUCTOR[dtype]
except KeyError:
return PySeries.new_object
except NameError:
raise ImportError(
"'numpy' is required for this functionality."
) # pragma: no cover
except NameError: # pragma: no cover
raise ImportError("'numpy' is required for this functionality.")


if not _DOCUMENTING:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SchemaError,
ShapeError,
)
except ImportError: # pragma: no cover
except ImportError:
# They are only redefined for documentation purposes
# when there is no binary yet

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

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


Expand Down Expand Up @@ -45,10 +45,8 @@ def _scan_ds_impl(
-------
"""
if not _PYARROW_AVAILABLE:
raise ImportError( # pragma: no cover
"'pyarrow' is required for scanning from pyarrow datasets."
)
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError("'pyarrow' is required for scanning from pyarrow datasets.")
return pl.from_arrow(ds.to_table(columns=with_columns)) # type: ignore


Expand Down
8 changes: 4 additions & 4 deletions py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@
)
from polars.utils import threadpool_size

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

try:
from polars.polars import PyDataFrame, PySeries

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

try:
import numpy as np

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

try:
import pyarrow as pa

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

if sys.version_info >= (3, 8):
Expand Down
20 changes: 8 additions & 12 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
from polars.polars import PyExpr

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

try:
import numpy as np

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


Expand Down Expand Up @@ -203,8 +203,8 @@ def __array_ufunc__(

args = [inp for inp in inputs if not isinstance(inp, Expr)]

def function(s: pli.Series) -> pli.Series:
return ufunc(s, *args, **kwargs) # pragma: no cover
def function(s: pli.Series) -> pli.Series: # pragma: no cover
return ufunc(s, *args, **kwargs)

if "dtype" in kwargs:
dtype = kwargs["dtype"]
Expand Down Expand Up @@ -5618,20 +5618,16 @@ def strptime(
└────────────┘
"""
if not issubclass(datatype, DataType):
raise ValueError(
f"expected: {DataType} got: {datatype}"
) # pragma: no cover
if not issubclass(datatype, DataType): # pragma: no cover
raise ValueError(f"expected: {DataType} got: {datatype}")
if datatype == Date:
return wrap_expr(self._pyexpr.str_parse_date(fmt, strict, exact))
elif datatype == Datetime:
return wrap_expr(self._pyexpr.str_parse_datetime(fmt, strict, exact))
elif datatype == Time:
return wrap_expr(self._pyexpr.str_parse_time(fmt, strict, exact))
else:
raise ValueError(
"dtype should be of type {Date, Datetime, Time}"
) # pragma: no cover
else: # pragma: no cover
raise ValueError("dtype should be of type {Date, Datetime, Time}")

def lengths(self) -> Expr:
"""
Expand Down
28 changes: 13 additions & 15 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
from polars.polars import PyDataFrame, PySeries

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

try:
import numpy as np

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

try:
Expand All @@ -70,20 +70,20 @@
import pyarrow.parquet

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

try:
import pandas as pd

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

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal # pragma: no cover
from typing_extensions import Literal

# A type variable used to refer to a polars.DataFrame or any subclass of it.
# Used to annotate DataFrame methods which returns the same type as self.
Expand Down Expand Up @@ -320,8 +320,8 @@ def __init__(
self._df = series_to_pydf(data, columns=columns)

elif _PANDAS_AVAILABLE and isinstance(data, pd.DataFrame):
if not _PYARROW_AVAILABLE:
raise ImportError( # pragma: no cover
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required for converting a pandas DataFrame to a polars DataFrame."
)
self._df = pandas_to_pydf(data, columns=columns)
Expand Down Expand Up @@ -819,8 +819,8 @@ def to_arrow(self) -> pa.Table:
Data types that do copy:
- CategoricalType
"""
if not _PYARROW_AVAILABLE:
raise ImportError( # pragma: no cover
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required for converting a polars DataFrame to an Arrow Table."
)
record_batches = self._df.to_arrow()
Expand Down Expand Up @@ -1101,10 +1101,8 @@ def to_pandas(
<class 'pandas.core.frame.DataFrame'>
"""
if not _PYARROW_AVAILABLE:
raise ImportError( # pragma: no cover
"'pyarrow' is required when using to_pandas()."
)
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError("'pyarrow' is required when using to_pandas().")
record_batches = self._df.to_pandas()
tbl = pa.Table.from_batches(record_batches)
return tbl.to_pandas(*args, date_as_object=date_as_object, **kwargs)
Expand Down Expand Up @@ -1443,8 +1441,8 @@ def write_parquet(
file = format_path(file)

if use_pyarrow:
if not _PYARROW_AVAILABLE:
raise ImportError( # pragma: no cover
if not _PYARROW_AVAILABLE: # pragma: no cover
raise ImportError(
"'pyarrow' is required when using 'write_parquet(..., use_pyarrow=True)'."
)

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 @@ -20,7 +20,7 @@
from polars.polars import py_hor_concat_df as _hor_concat_df

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


Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
try:
from polars.polars import ipc_schema as _ipc_schema
from polars.polars import parquet_schema as _parquet_schema
except ImportError: # pragma: no cover
except ImportError:
pass


Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal # pragma: no cover
from typing_extensions import Literal

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

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


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

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

# Used to type any type or subclass of LazyFrame.
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/lazy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
from polars.polars import spearman_rank_corr as pyspearman_rank_corr

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

try:
import numpy as np

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

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal # pragma: no cover
from typing_extensions import Literal


def col(
Expand Down

0 comments on commit 34b8adf

Please sign in to comment.