Skip to content

Commit

Permalink
Clean imports (#1839)
Browse files Browse the repository at this point in the history
As we define the public api in `polars/__init__.py`, the creation of `__all__` has also been done there.
  • Loading branch information
zundertj committed Nov 21, 2021
1 parent 5717aa4 commit bf44119
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 160 deletions.
146 changes: 138 additions & 8 deletions py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,34 @@ def version() -> str:
# this is only useful for documentation
warnings.warn("polars binary missing!")

from polars.cfg import Config # flake8: noqa. We do not export in __all__
from polars.convert import from_arrow, from_dict, from_dicts, from_pandas, from_records
from polars.datatypes import (
Boolean,
Categorical,
DataType,
Date,
Datetime,
Float32,
Float64,
Int8,
Int16,
Int32,
Int64,
List,
Object,
Time,
UInt8,
UInt16,
UInt32,
UInt64,
Utf8,
)
from polars.internals.expr import Expr
from polars.internals.frame import DataFrame, wrap_df # TODO: remove need for wrap_df
from polars.internals.frame import ( # flake8: noqa # TODO: remove need for wrap_df
DataFrame,
wrap_df,
)
from polars.internals.functions import (
arg_where,
concat,
Expand Down Expand Up @@ -59,16 +85,120 @@ def version() -> str:
sum,
tail,
)
from polars.internals.lazy_functions import to_list
from polars.internals.lazy_functions import to_list as list
from polars.internals.lazy_functions import var
from polars.internals.series import Series, wrap_s # TODO: remove need for wrap_s
from polars.internals.series import ( # flake8: noqa # TODO: remove need for wrap_s
Series,
wrap_s,
)
from polars.internals.whenthen import when
from polars.io import (
read_csv,
read_ipc,
read_ipc_schema,
read_json,
read_parquet,
read_sql,
scan_csv,
scan_ipc,
scan_parquet,
)
from polars.string_cache import StringCache

# TODO: remove wildcard imports
from .convert import *
from .datatypes import *
from .io import *
from .string_cache import StringCache
__all__ = [
"DataFrame",
"Series",
"LazyFrame",
# polars.datatypes
"DataType",
"Int8",
"Int16",
"Int32",
"Int64",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"Float32",
"Float64",
"Boolean",
"Utf8",
"List",
"Date",
"Datetime",
"Time",
"Object",
"Categorical",
# polars.io
"read_csv",
"read_parquet",
"read_json",
"read_sql",
"read_ipc",
"scan_csv",
"scan_ipc",
"scan_parquet",
"read_ipc_schema",
# polars.stringcache
"StringCache",
# polars.config
"Config",
# polars.internal.when
"when",
# polars.internal.expr
"Expr",
# polars.internal.functions
"arg_where",
"concat",
"date_range",
"get_dummies",
"repeat",
# polars.internal.lazy_functions
"col",
"count",
"std",
"var",
"max",
"min",
"sum",
"mean",
"avg",
"median",
"n_unique",
"first",
"last",
"head",
"tail",
"lit",
"pearson_corr",
"spearman_rank_corr",
"cov",
"map",
"apply",
"map_binary",
"fold",
"any",
"all",
"groups",
"quantile",
"arange",
"argsort_by",
"concat_str",
"concat_list",
"collect_all",
"exclude",
"format",
"datetime", # named _datetime, see import above
"date", # name _date, see import above
"list", # named to_list, see import above
"select",
"var",
# polars.convert
"from_dict",
"from_dicts",
"from_records",
"from_arrow",
"from_pandas",
]

__version__ = version()
4 changes: 0 additions & 4 deletions py-polars/polars/cfg.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import os
from typing import Type

__all__ = [
"Config",
]

from polars.string_cache import toggle_string_cache


Expand Down
9 changes: 0 additions & 9 deletions py-polars/polars/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
_PYARROW_AVAILABLE = False


__all__ = [
"from_dict",
"from_dicts",
"from_records",
"from_arrow",
"from_pandas",
]


def from_dict(
data: Dict[str, Sequence[Any]],
columns: Optional[Sequence[str]] = None,
Expand Down
27 changes: 0 additions & 27 deletions py-polars/polars/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,6 @@

from _ctypes import _SimpleCData

__all__ = [
"DataType",
"Int8",
"Int16",
"Int32",
"Int64",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"Float32",
"Float64",
"Boolean",
"Utf8",
"List",
"Date",
"Datetime",
"Time",
"Object",
"Categorical",
"DTYPES",
"DTYPE_TO_FFINAME",
"date_like_to_physical",
"dtype_to_ctype",
"py_type_to_dtype",
]


class DataType:
pass
Expand Down
7 changes: 0 additions & 7 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
Utf8,
)

__all__ = [
"Expr",
"ExprStringNameSpace",
"ExprDateTimeNameSpace",
"expr_to_lit_or_expr",
]


def _selection_to_pyexpr_list(
exprs: Union[str, "Expr", Sequence[Union[str, "Expr"]]]
Expand Down
4 changes: 0 additions & 4 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
except ImportError:
_PANDAS_AVAILABLE = False

__all__ = [
"DataFrame",
]


def wrap_df(df: "PyDataFrame") -> "DataFrame":
return DataFrame._from_pydf(df)
Expand Down
4 changes: 1 addition & 3 deletions py-polars/polars/internals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import numpy as np

from polars import internals as pli
from polars.datatypes import Datetime, py_type_to_dtype

try:
from polars.datatypes import Datetime, py_type_to_dtype
from polars.polars import concat_df as _concat_df
from polars.polars import concat_lf as _concat_lf
from polars.polars import concat_series as _concat_series
Expand All @@ -16,8 +16,6 @@
except ImportError:
_DOCUMENTING = True

__all__ = ["get_dummies", "concat", "repeat", "arg_where", "date_range"]


def get_dummies(df: "pli.DataFrame") -> "pli.DataFrame":
"""
Expand Down
4 changes: 0 additions & 4 deletions py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
from polars.datatypes import DataType, py_type_to_dtype
from polars.utils import _process_null_values

__all__ = [
"LazyFrame",
]


def wrap_ldf(ldf: "PyLazyFrame") -> "LazyFrame":
return LazyFrame._from_pyldf(ldf)
Expand Down
42 changes: 0 additions & 42 deletions py-polars/polars/internals/lazy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,6 @@
_DOCUMENTING = True


__all__ = [
"col",
"count",
"to_list",
"std",
"var",
"max",
"min",
"sum",
"mean",
"avg",
"median",
"n_unique",
"first",
"last",
"head",
"tail",
"lit",
"pearson_corr",
"spearman_rank_corr",
"cov",
"map",
"apply",
"map_binary",
"fold",
"any",
"all",
"groups",
"quantile",
"arange",
"argsort_by",
"concat_str",
"concat_list",
"collect_all",
"exclude",
"format",
"_datetime",
"_date",
"select",
]


def col(
name: Union[
str, tp.List[str], tp.List[Type[DataType]], "pli.Series", Type[DataType]
Expand Down
4 changes: 0 additions & 4 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
except ImportError:
_PANDAS_AVAILABLE = False

__all__ = [
"Series",
]


def match_dtype(value: Any, dtype: "Type[DataType]") -> Any:
"""
Expand Down
2 changes: 0 additions & 2 deletions py-polars/polars/internals/whenthen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from polars import internals as pli

__all__ = ["when"]


class WhenThenThen:
"""
Expand Down
12 changes: 0 additions & 12 deletions py-polars/polars/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@
except ImportError:
_WITH_FSSPEC = False

__all__ = [
"read_csv",
"read_parquet",
"read_json",
"read_sql",
"read_ipc",
"scan_csv",
"scan_ipc",
"scan_parquet",
"read_ipc_schema",
]


def _process_http_file(path: str) -> BytesIO:
with urlopen(path) as f:
Expand Down
5 changes: 0 additions & 5 deletions py-polars/polars/string_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
except ImportError:
_DOCUMENTING = True

__all__ = [
"StringCache",
"toggle_string_cache",
]


class StringCache:
"""
Expand Down

0 comments on commit bf44119

Please sign in to comment.