Skip to content

Commit

Permalink
Fix bugs with field mapping and lint issue (#346)
Browse files Browse the repository at this point in the history
* Fix bugs with field mapping:

1. If no permission to call _mapping, return readable error
2. If index is wildcard, fix issues with user warnings

* Fixing lint issues

* Removing trailing backslashes in doc

* Remove pandas/matplotlib deprecation warning

This warning is due to a conflict between
pandas/matplotlib that may be resolved in a later
version. For now, ignore the warning so CI works.
  • Loading branch information
stevedodson committed Mar 30, 2021
1 parent 985afe7 commit 1040160
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 2,691 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -197,13 +197,13 @@ currently using a minimum version of PyCharm 2019.2.4.
* To run the automatic formatter and check for lint issues run

``` bash
> nox -s format`
> nox -s format
```

* To test specific versions of Python run

``` bash
> nox -s test-3.8`
> nox -s test-3.8
```

### Documentation
Expand Down
18 changes: 13 additions & 5 deletions eland/field_mappings.py
Expand Up @@ -202,6 +202,11 @@ def __init__(
)

get_mapping = client.indices.get_mapping(index=index_pattern)
if not get_mapping: # dict is empty
raise ValueError(
f"Can not get mapping for {index_pattern} "
f"check indexes exist and client has permission to get mapping."
)

# Get all fields (including all nested) and then all field_caps
all_fields = FieldMappings._extract_fields_from_mapping(get_mapping)
Expand Down Expand Up @@ -307,7 +312,10 @@ def flatten(x, name=""):
if field_type == "date" and "format" in x:
date_format = x["format"]
# If there is a conflicting type, warn - first values added wins
if field_name in fields and fields[field_name] != field_type:
if field_name in fields and fields[field_name] != (
field_type,
date_format,
):
warnings.warn(
f"Field {field_name} has conflicting types "
f"{fields[field_name]} != {field_type}",
Expand Down Expand Up @@ -403,14 +411,14 @@ def _create_capability_matrix(all_fields, source_fields, all_fields_caps):

if "non_aggregatable_indices" in vv:
warnings.warn(
"Field {} has conflicting aggregatable fields across indexes {}",
format(field, vv["non_aggregatable_indices"]),
f"Field {field} has conflicting aggregatable fields across indexes "
f"{str(vv['non_aggregatable_indices'])}",
UserWarning,
)
if "non_searchable_indices" in vv:
warnings.warn(
"Field {} has conflicting searchable fields across indexes {}",
format(field, vv["non_searchable_indices"]),
f"Field {field} has conflicting searchable fields across indexes "
f"{str(vv['non_searchable_indices'])}",
UserWarning,
)

Expand Down
8 changes: 0 additions & 8 deletions eland/ml/transformers/__init__.py
Expand Up @@ -65,19 +65,15 @@ def get_model_transformer(model: Any, **kwargs: Any) -> ModelTransformer:
try:
from .xgboost import _MODEL_TRANSFORMERS as _XGBOOST_MODEL_TRANSFORMERS
from .xgboost import (
XGBClassifier,
XGBoostClassifierTransformer,
XGBoostForestTransformer,
XGBoostRegressorTransformer,
XGBRegressor,
)

__all__ += [
"XGBoostClassifierTransformer",
"XGBClassifier",
"XGBoostForestTransformer",
"XGBoostRegressorTransformer",
"XGBRegressor",
]
_MODEL_TRANSFORMERS.update(_XGBOOST_MODEL_TRANSFORMERS)
except ImportError:
Expand All @@ -86,16 +82,12 @@ def get_model_transformer(model: Any, **kwargs: Any) -> ModelTransformer:
try:
from .lightgbm import _MODEL_TRANSFORMERS as _LIGHTGBM_MODEL_TRANSFORMERS
from .lightgbm import (
LGBMClassifier,
LGBMClassifierTransformer,
LGBMForestTransformer,
LGBMRegressor,
LGBMRegressorTransformer,
)

__all__ += [
"LGBMRegressor",
"LGBMClassifier",
"LGBMForestTransformer",
"LGBMRegressorTransformer",
"LGBMClassifierTransformer",
Expand Down

0 comments on commit 1040160

Please sign in to comment.