Commit 8e86f3dc authored by Mitar's avatar Mitar
Browse files

Added style and type checks.

parent 561a3106
Pipeline #15521791 failed with stage
in 2 minutes and 48 seconds
......@@ -16,3 +16,34 @@ build_summing_image:
only:
- master
style_check:
stage: build
image: datadrivendiscovery/ubuntu-xenial-python36-go-js
script:
- pycodestyle primitives/test_primitives
type_check:
stage: build
image: datadrivendiscovery/ubuntu-xenial-python36-go-js
variables:
DEPENDENCY_REF: master
script:
- cd primitives
- pip3 install -r requirements.txt
- pip3 install .
- git clone https://gitlab.com/datadrivendiscovery/metadata.git
- cd metadata
- git checkout ${DEPENDENCY_REF}
- cd ..
- git clone https://gitlab.com/datadrivendiscovery/primitive-interfaces.git
- cd primitive-interfaces
# TODO: Change to {DEPENDENCY_REF}.
- git checkout devel
- cd ..
- MYPYPATH=metadata:primitive-interfaces mypy test_primitives
[pycodestyle]
max-line-length = 200
[metadata]
description-file = README.md
[mypy]
warn_redundant_casts = True
# TODO: Enable back once false positives are fixed.
# See: https://github.com/python/mypy/issues/4412
#warn_unused_ignores = True
warn_unused_configs = True
disallow_untyped_defs = True
# TODO: Remove once this is fixed: https://github.com/python/mypy/issues/4300
[mypy-d3m_metadata.container.list]
ignore_errors = True
# TODO: Remove once this is fixed: https://github.com/python/mypy/pull/4384#issuecomment-354033177
[mypy-primitive_interfaces.distance]
ignore_errors = True
......@@ -115,7 +115,7 @@ class IncrementPrimitive(transformer.TransformerPrimitiveBase[Inputs, Outputs, H
if 'inputs' not in arguments:
return output_metadata
inputs_metadata = arguments['inputs']
inputs_metadata = typing.cast(metadata_module.DataMetadata, arguments['inputs'])
dimension_index = 0
while True:
metadata = inputs_metadata.query((metadata_module.ALL_ELEMENTS,) * dimension_index)
......
......@@ -81,7 +81,7 @@ class MonomialPrimitive(supervised_learning.SupervisedLearnerPrimitiveBase[Input
result = (self._a * input + self.hyperparams['bias'] for input in inputs)
# We convert a regular list to container list which supports metadata attribute.
outputs = container.List(result)
outputs: container.List[float] = container.List[float](result)
# We clear old metadata (but which keeps history and link to inputs metadata) and set new metadata.
# "for_value" tells that this new metadata will be associated with "outputs",
......
......@@ -97,8 +97,11 @@ class SumPrimitive(base.SingletonOutputMixin[Inputs, Outputs, None, Hyperparams]
def produce(self, *, inputs: Inputs, timeout: float = None, iterations: int = None) -> base.CallResult[Outputs]:
# In the future, we should store here data in Arrow format into
# Plasma store and just pass an ObjectId of data over HTTP.
value = inputs.view(numpy.ndarray)
data = pickle.dumps(value)
if isinstance(inputs, container.ndarray):
value = inputs.view(numpy.ndarray)
data = pickle.dumps(value)
else:
data = pickle.dumps(inputs)
# TODO: Retry if connection fails.
# This connection can sometimes fail because the service inside a Docker container
......@@ -115,8 +118,8 @@ class SumPrimitive(base.SingletonOutputMixin[Inputs, Outputs, None, Hyperparams]
})
response = connection.getresponse()
if response.code != 200:
raise ValueError("Invalid HTTP response code: {code}".format(code=response.code))
if response.status != 200:
raise ValueError("Invalid HTTP response status: {status}".format(status=response.status))
result = int(response.read())
......@@ -148,7 +151,7 @@ class SumPrimitive(base.SingletonOutputMixin[Inputs, Outputs, None, Hyperparams]
if 'inputs' not in arguments:
return output_metadata
inputs_metadata = arguments['inputs']
inputs_metadata = typing.cast(metadata_module.DataMetadata, arguments['inputs'])
dimension_index = 0
while True:
metadata = inputs_metadata.query((metadata_module.ALL_ELEMENTS,) * dimension_index)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment