Skip to content

Commit

Permalink
Add isort, rename Nox session to 'format'
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Oct 15, 2020
1 parent 18fb4af commit 05a24cb
Show file tree
Hide file tree
Showing 75 changed files with 250 additions and 241 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ currently using a minimum version of PyCharm 2019.2.4.
- Run `pytest --nbval` to validate install
- To test specific versions of Python use `nox -s test-3.8`
- To run the automatic formatter and check for lint issues
run `nox -s blacken`
run `nox -s format`


### Documentation
Expand Down
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

# -- Path setup --------------------------------------------------------------

import datetime
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# 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
import datetime

sys.path.insert(0, os.path.abspath("../sphinxext"))
sys.path.extend(
Expand Down
22 changes: 11 additions & 11 deletions eland/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
# specific language governing permissions and limitations
# under the License.

from eland._version import ( # noqa: F401
__title__,
__description__,
__url__,
__version__,
from ._version import ( # noqa: F401
__author__,
__author_email__,
__description__,
__maintainer__,
__maintainer_email__,
__title__,
__url__,
__version__,
)
from eland.common import SortOrder
from eland.index import Index
from eland.ndframe import NDFrame
from eland.series import Series
from eland.dataframe import DataFrame
from eland.etl import pandas_to_eland, eland_to_pandas, read_es, read_csv, csv_to_eland
from .common import SortOrder
from .dataframe import DataFrame
from .etl import csv_to_eland, eland_to_pandas, pandas_to_eland, read_csv, read_es
from .index import Index
from .ndframe import NDFrame
from .series import Series

__all__ = [
"DataFrame",
Expand Down
4 changes: 2 additions & 2 deletions eland/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# under the License.

from abc import ABC, abstractmethod
from typing import List, Optional, TYPE_CHECKING, Union
from eland import SortOrder
from typing import TYPE_CHECKING, List, Optional, Union

from eland import SortOrder

if TYPE_CHECKING:
import pandas as pd # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion eland/arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from abc import ABC, abstractmethod
from io import StringIO
from typing import Union, List, TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, List, Union

import numpy as np # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion eland/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import re
import warnings
from enum import Enum
from typing import Union, List, Tuple, cast, Callable, Any, Optional, Dict
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast

import numpy as np # type: ignore
import pandas as pd # type: ignore
Expand Down
10 changes: 5 additions & 5 deletions eland/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# specific language governing permissions and limitations
# under the License.

import re
import sys
import warnings
from io import StringIO
import re
from typing import List, Optional, Sequence, Union, Tuple
from typing import List, Optional, Sequence, Tuple, Union

import numpy as np
import pandas as pd
Expand All @@ -34,12 +34,12 @@
from pandas.util._validators import validate_bool_kwarg

import eland.plotting as gfx
from eland.ndframe import NDFrame
from eland.series import Series
from eland.common import DEFAULT_NUM_ROWS_DISPLAYED, docstring_parameter
from eland.filter import BooleanFilter
from eland.utils import deprecated_api, is_valid_attr_name
from eland.groupby import GroupByDataFrame
from eland.ndframe import NDFrame
from eland.series import Series
from eland.utils import deprecated_api, is_valid_attr_name


class DataFrame(NDFrame):
Expand Down
9 changes: 5 additions & 4 deletions eland/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
# under the License.

import csv
from typing import Generator, Union, List, Tuple, Optional, Mapping, Dict, Any
from collections import deque
from typing import Any, Dict, Generator, List, Mapping, Optional, Tuple, Union

import pandas as pd # type: ignore
from elasticsearch import Elasticsearch # type: ignore
from elasticsearch.helpers import parallel_bulk # type: ignore
from pandas.io.parsers import _c_parser_defaults # type: ignore

from eland import DataFrame
from eland.common import DEFAULT_CHUNK_SIZE, ensure_es_client
from eland.field_mappings import FieldMappings, verify_mapping_compatibility
from eland.common import ensure_es_client, DEFAULT_CHUNK_SIZE
from eland.utils import deprecated_api
from elasticsearch import Elasticsearch # type: ignore
from elasticsearch.helpers import parallel_bulk # type: ignore


@deprecated_api("eland.DataFrame()")
Expand Down
27 changes: 14 additions & 13 deletions eland/field_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,32 @@
# under the License.

import warnings
from typing import (
TYPE_CHECKING,
Any,
Dict,
List,
Mapping,
NamedTuple,
Optional,
Set,
Tuple,
)

import numpy as np
import pandas as pd
from pandas.core.dtypes.common import (
is_float_dtype,
is_bool_dtype,
is_integer_dtype,
is_datetime_or_timedelta_dtype,
is_float_dtype,
is_integer_dtype,
is_string_dtype,
)
from pandas.core.dtypes.inference import is_list_like
from typing import (
NamedTuple,
Optional,
Mapping,
Dict,
Any,
Tuple,
TYPE_CHECKING,
List,
Set,
)

if TYPE_CHECKING:
from elasticsearch import Elasticsearch

from eland import DataFrame


Expand Down
2 changes: 1 addition & 1 deletion eland/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Originally based on code in MIT-licensed pandasticsearch filters

from typing import Dict, Any, List, Optional, Union, cast
from typing import Any, Dict, List, Optional, Union, cast


class BooleanFilter:
Expand Down
3 changes: 2 additions & 1 deletion eland/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING, List

from eland.query_compiler import QueryCompiler

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion eland/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional, TextIO, TYPE_CHECKING
from typing import TYPE_CHECKING, Optional, TextIO

from eland.utils import deprecated_api

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion eland/ml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from eland.ml.ml_model import MLModel, ImportedMLModel
from eland.ml.ml_model import ImportedMLModel, MLModel

__all__ = [
"MLModel",
Expand Down
2 changes: 1 addition & 1 deletion eland/ml/_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import gzip
import json
from abc import ABC
from typing import Sequence, Dict, Any, Optional, List
from typing import Any, Dict, List, Optional, Sequence


def add_if_exists(d: Dict[str, Any], k: str, v: Any) -> None:
Expand Down
25 changes: 17 additions & 8 deletions eland/ml/ml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,40 @@
# specific language governing permissions and limitations
# under the License.

from typing import List, Union, cast, Optional, Dict, TYPE_CHECKING, Any, Tuple
import warnings
import numpy as np # type: ignore
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, cast

import elasticsearch # type: ignore
from .common import TYPE_REGRESSION, TYPE_CLASSIFICATION
from .transformers import get_model_transformer
import numpy as np # type: ignore

from eland.common import ensure_es_client, es_version
from eland.utils import deprecated_api

from .common import TYPE_CLASSIFICATION, TYPE_REGRESSION
from .transformers import get_model_transformer

if TYPE_CHECKING:
from elasticsearch import Elasticsearch # noqa: F401

# Try importing each ML lib separately so mypy users don't have to
# have both installed to use type-checking.
try:
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor # type: ignore # noqa: F401
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor # type: ignore # noqa: F401
from sklearn.ensemble import ( # type: ignore # noqa: F401
RandomForestClassifier,
RandomForestRegressor,
)
from sklearn.tree import ( # type: ignore # noqa: F401
DecisionTreeClassifier,
DecisionTreeRegressor,
)
except ImportError:
pass
try:
from xgboost import XGBRegressor, XGBClassifier # type: ignore # noqa: F401
from xgboost import XGBClassifier, XGBRegressor # type: ignore # noqa: F401
except ImportError:
pass
try:
from lightgbm import LGBMRegressor, LGBMClassifier # type: ignore # noqa: F401
from lightgbm import LGBMClassifier, LGBMRegressor # type: ignore # noqa: F401
except ImportError:
pass

Expand Down
14 changes: 7 additions & 7 deletions eland/ml/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import inspect
from typing import Any, Dict, Type
from .base import ModelTransformer

from .base import ModelTransformer

__all__ = ["get_model_transformer"]
_MODEL_TRANSFORMERS: Dict[type, Type[ModelTransformer]] = {}
Expand All @@ -42,13 +42,13 @@ def get_model_transformer(model: Any, **kwargs: Any) -> ModelTransformer:


try:
from .sklearn import _MODEL_TRANSFORMERS as _SKLEARN_MODEL_TRANSFORMERS
from .sklearn import (
SKLearnDecisionTreeTransformer,
SKLearnForestClassifierTransformer,
SKLearnForestRegressorTransformer,
SKLearnForestTransformer,
SKLearnTransformer,
_MODEL_TRANSFORMERS as _SKLEARN_MODEL_TRANSFORMERS,
)

__all__ += [
Expand All @@ -63,13 +63,13 @@ def get_model_transformer(model: Any, **kwargs: Any) -> ModelTransformer:
pass

try:
from .xgboost import _MODEL_TRANSFORMERS as _XGBOOST_MODEL_TRANSFORMERS
from .xgboost import (
XGBoostClassifierTransformer,
XGBClassifier,
XGBoostClassifierTransformer,
XGBoostForestTransformer,
XGBoostRegressorTransformer,
XGBRegressor,
_MODEL_TRANSFORMERS as _XGBOOST_MODEL_TRANSFORMERS,
)

__all__ += [
Expand All @@ -84,13 +84,13 @@ def get_model_transformer(model: Any, **kwargs: Any) -> ModelTransformer:
pass

try:
from .lightgbm import _MODEL_TRANSFORMERS as _LIGHTGBM_MODEL_TRANSFORMERS
from .lightgbm import (
LGBMRegressor,
LGBMClassifier,
LGBMClassifierTransformer,
LGBMForestTransformer,
LGBMRegressor,
LGBMRegressorTransformer,
LGBMClassifierTransformer,
_MODEL_TRANSFORMERS as _LIGHTGBM_MODEL_TRANSFORMERS,
)

__all__ += [
Expand Down
3 changes: 2 additions & 1 deletion eland/ml/transformers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Sequence, Optional, Any
from typing import Any, Optional, Sequence

from .._model_serializer import ModelSerializer


Expand Down
9 changes: 5 additions & 4 deletions eland/ml/transformers/lightgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional, List, Dict, Any, Type
from .base import ModelTransformer
from typing import Any, Dict, List, Optional, Type

from .._model_serializer import Ensemble, Tree, TreeNode
from ..common import TYPE_CLASSIFICATION, TYPE_REGRESSION
from .._optional import import_optional_dependency
from ..common import TYPE_CLASSIFICATION, TYPE_REGRESSION
from .base import ModelTransformer

import_optional_dependency("lightgbm", on_version="warn")

from lightgbm import Booster, LGBMRegressor, LGBMClassifier # type: ignore
from lightgbm import Booster, LGBMClassifier, LGBMRegressor # type: ignore


def transform_decider(decider: str) -> str:
Expand Down
Loading

0 comments on commit 05a24cb

Please sign in to comment.