Commit 8f786c45 authored by Mitar's avatar Mitar

Fixing typing.

parent af4afcf9
Pipeline #212587243 failed with stage
in 1 minute and 42 seconds
......@@ -5,21 +5,14 @@ max-line-length = 200
description-file = README.md
[mypy]
pretty = True
show_error_context = True
show_column_numbers = True
ignore_missing_imports = True
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_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.container.list]
ignore_errors = True
# TODO: Remove once this is fixed: https://github.com/python/mypy/issues/4300
[mypy-d3m.metadata.hyperparams]
ignore_errors = True
# TODO: Remove once this is fixed: https://github.com/python/mypy/pull/4384#issuecomment-354033177
[mypy-d3m.primitive_interfaces.distance]
ignore_errors = True
disallow_incomplete_defs = True
# TODO: Enable eventually.
# disallow_untyped_decorators = True
import os.path
import typing
import numpy as np # type: ignore
import numpy as np
from d3m import container, utils, exceptions
from d3m.metadata import hyperparams, base as metadata_base
......
import os.path
import typing
import numpy as np # type: ignore
import numpy as np
from d3m import container, utils
from d3m.metadata import hyperparams, base as metadata_base
......
......@@ -80,6 +80,8 @@ class FailPrimitive(transformer.TransformerPrimitiveBase[Inputs, Outputs, Hyperp
'primitive_family': metadata_base.PrimitiveFamily.OPERATOR,
})
_fitted: bool
def __init__(self, *, hyperparams: Hyperparams) -> None:
super().__init__(hyperparams=hyperparams)
self._conditional_fail('__init__')
......
import os
import typing
import numpy # type: ignore
import frozendict # type: ignore
import numpy
import frozendict
from d3m import container, utils as d3m_utils
from d3m.base import primitives
......
......@@ -75,14 +75,19 @@ class MonomialPrimitive(supervised_learning.SupervisedLearnerPrimitiveBase[Input
'primitive_family': metadata_base.PrimitiveFamily.REGRESSION,
})
_a: float
_training_inputs: typing.Optional[Inputs]
_training_outputs: typing.Optional[Outputs]
_fitted: bool
# Random seed is not needed, but we need it in tests to test which random seed was passed to a primitive.
def __init__(self, *, hyperparams: Hyperparams, random_seed: int = 0) -> None:
super().__init__(hyperparams=hyperparams, random_seed=random_seed)
self._a: float = 0
self._training_inputs: Inputs = None
self._training_outputs: Outputs = None
self._fitted: bool = False
self._a = 0
self._training_inputs = None
self._training_outputs = None
self._fitted = False
def produce(self, *, inputs: Inputs, timeout: float = None, iterations: int = None) -> base.CallResult[Outputs]:
if self._a is None:
......@@ -109,7 +114,7 @@ class MonomialPrimitive(supervised_learning.SupervisedLearnerPrimitiveBase[Input
if self._fitted:
return base.CallResult(None)
if not self._training_inputs or not self._training_inputs:
if self._training_inputs is None or self._training_outputs is None:
raise ValueError("Missing training data.")
quotients = [output / input for output, input in zip(self._training_outputs, self._training_inputs) if input != 0]
......
import os.path
import typing
import numpy as np # type: ignore
import numpy as np
from d3m import container, utils
from d3m.metadata import hyperparams, base as metadata_base
......
......@@ -9,8 +9,8 @@ import subprocess
import time
import typing
import prctl # type: ignore
import psycopg2 # type: ignore
import prctl
import psycopg2
from d3m import container, utils
from d3m.metadata import base as metadata_base, hyperparams
......@@ -92,13 +92,21 @@ class PostgreSQLPrimitive(transformer.TransformerPrimitiveBase[Inputs, Outputs,
'primitive_family': metadata_base.PrimitiveFamily.OPERATOR,
})
_connection: typing.Optional[psycopg2.connection]
_process: typing.Optional[subprocess.Popen]
_postgresql_base: typing.Optional[str]
_config_dir: str
_data_dir: str
_run_dir: str
_config_file: str
def __init__(self, *, hyperparams: Hyperparams, temporary_directory: str = None) -> None:
super().__init__(hyperparams=hyperparams, temporary_directory=temporary_directory)
# Initialize it early so that "__del__" has access to these attributes.
self._connection: psycopg2.connection = None
self._process: subprocess.Popen = None
self._postgresql_base: str = None
self._connection = None
self._process = None
self._postgresql_base = None
self._postgresql_base = tempfile.mkdtemp()
os.chmod(self._postgresql_base, 0o755)
......@@ -203,9 +211,14 @@ class PostgreSQLPrimitive(transformer.TransformerPrimitiveBase[Inputs, Outputs,
connection_error = error
time.sleep(0.1)
else:
raise connection_error
if connection_error is None:
raise TimeoutError("Timeout waiting for the connection.")
else:
raise connection_error
def produce(self, *, inputs: Inputs, timeout: float = None, iterations: int = None) -> base.CallResult[Outputs]:
assert self._connection is not None
with self._connection.cursor() as cursor:
cursor.execute("SELECT 42;")
return base.CallResult(container.List([cursor.fetchone()[0]], generate_metadata=True))
......
import os.path
import typing
import pandas as pd # type: ignore
import pandas as pd
from d3m import container, utils
from d3m.metadata import hyperparams, base as metadata_base
......
......@@ -2,7 +2,7 @@ import os.path
import time
import typing
import numpy # type: ignore
import numpy
from d3m import container, exceptions, utils
from d3m.metadata import base as metadata_base, hyperparams
......
import os.path
import typing
import numpy # type: ignore
import numpy
from d3m import container, utils
from d3m.metadata import base as metadata_base, hyperparams
......@@ -151,4 +151,4 @@ class RandomPrimitive(generator.GeneratorPrimitiveBase[Outputs, None, Hyperparam
A dict of values for each produce method wrapped inside ``MultiCallResult``.
"""
return self._fit_multi_produce(produce_methods=produce_methods, timeout=timeout, iterations=iterations, inputs=inputs) # type: ignore
return self._fit_multi_produce(produce_methods=produce_methods, timeout=timeout, iterations=iterations, inputs=inputs)
......@@ -63,14 +63,19 @@ class RandomClassifierPrimitive(SupervisedLearnerPrimitiveBase[Inputs, Outputs,
],
})
_random: random.Random
_training_outputs: typing.Optional[Outputs]
_fitted: bool
_classes: typing.Optional[typing.List]
def __init__(self, *, hyperparams: Hyperparams, random_seed: int = 0) -> None:
super().__init__(hyperparams=hyperparams, random_seed=random_seed)
self._random: random.Random = random.Random()
self._random = random.Random()
self._random.seed(random_seed)
self._training_outputs: Outputs = None
self._training_outputs = None
self._fitted = False
self._classes: typing.List = []
self._classes = []
def set_training_data(self, *, inputs: Inputs, outputs: Outputs) -> None:
self._training_outputs = outputs
......
......@@ -3,7 +3,7 @@ import pickle
import typing
from http import client
import numpy # type: ignore
import numpy
from d3m import container, utils
from d3m.metadata import base as metadata_base, hyperparams
......
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