diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed3cdb5..b600ce70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [5.4.2] + +### Fixed + + * Fix on find_dotenv call + ## [5.4.1] ### Changed diff --git a/cognite/extractorutils/__init__.py b/cognite/extractorutils/__init__.py index eb3e6d9e..41bc845a 100644 --- a/cognite/extractorutils/__init__.py +++ b/cognite/extractorutils/__init__.py @@ -16,5 +16,5 @@ Cognite extractor utils is a Python package that simplifies the development of new extractors. """ -__version__ = "5.4.1" +__version__ = "5.4.2" from .base import Extractor diff --git a/cognite/extractorutils/base.py b/cognite/extractorutils/base.py index f3b1f196..752c31d1 100644 --- a/cognite/extractorutils/base.py +++ b/cognite/extractorutils/base.py @@ -240,7 +240,7 @@ def __enter__(self) -> "Extractor": if str(os.getenv("COGNITE_FUNCTION_RUNTIME", False)).lower() != "true": # Environment Variables - env_file_path = find_dotenv() + env_file_path = find_dotenv(usecwd=True) if env_file_path: load_dotenv(dotenv_path=env_file_path, override=True) dotenv_message = f"Successfully ingested environment variables from {env_file_path}" diff --git a/cognite/extractorutils/uploader/time_series.py b/cognite/extractorutils/uploader/time_series.py index 6242e028..89b16e95 100644 --- a/cognite/extractorutils/uploader/time_series.py +++ b/cognite/extractorutils/uploader/time_series.py @@ -46,7 +46,9 @@ MAX_DATAPOINT_VALUE = 1e100 MIN_DATAPOINT_VALUE = -1e100 -DataPoint = Tuple[Union[int, float, datetime], Union[int, float, str]] +TimeStamp = Union[int, datetime] + +DataPoint = Union[Tuple[TimeStamp, float], Tuple[TimeStamp, str]] DataPointList = List[DataPoint] diff --git a/cognite/extractorutils/uploader_extractor.py b/cognite/extractorutils/uploader_extractor.py index 4bb937c4..6859eb0c 100644 --- a/cognite/extractorutils/uploader_extractor.py +++ b/cognite/extractorutils/uploader_extractor.py @@ -118,17 +118,23 @@ def handle_output(self, output: CdfTypes) -> None: if isinstance(peek, Event): for event in peekable_output: event = self._apply_middleware(event) - self.event_queue.add_to_upload_queue(event) + if isinstance(event, Event): + self.event_queue.add_to_upload_queue(event) + elif isinstance(peek, RawRow): for raw_row in peekable_output: - for row in raw_row.rows: - row = self._apply_middleware(row) - self.raw_queue.add_to_upload_queue(database=raw_row.db_name, table=raw_row.table_name, raw_row=row) + if isinstance(raw_row, RawRow): + for row in raw_row.rows: + row = self._apply_middleware(row) + self.raw_queue.add_to_upload_queue( + database=raw_row.db_name, table=raw_row.table_name, raw_row=row + ) elif isinstance(peek, InsertDatapoints): - for datapoints in peekable_output: - self.time_series_queue.add_to_upload_queue( - id=datapoints.id, external_id=datapoints.external_id, datapoints=datapoints.datapoints - ) + for dp in peekable_output: + if isinstance(dp, InsertDatapoints): + self.time_series_queue.add_to_upload_queue( + id=dp.id, external_id=dp.external_id, datapoints=dp.datapoints + ) else: raise ValueError(f"Unexpected type: {type(peek)}") diff --git a/cognite/extractorutils/uploader_types.py b/cognite/extractorutils/uploader_types.py index 8510f541..69ae0814 100644 --- a/cognite/extractorutils/uploader_types.py +++ b/cognite/extractorutils/uploader_types.py @@ -1,5 +1,4 @@ -from datetime import datetime -from typing import Iterable, List, Optional, Tuple, Union +from typing import Iterable, List, Optional, Union from cognite.client.data_classes import Event as _Event from cognite.client.data_classes import Row as _Row @@ -11,17 +10,11 @@ from typing_extensions import TypeAlias -TimeStamp = Union[int, datetime] +from cognite.extractorutils.uploader.time_series import DataPoint class InsertDatapoints: - def __init__( - self, - *, - id: Optional[int] = None, - external_id: Optional[str] = None, - datapoints: Union[List[Tuple[TimeStamp, float]], List[Tuple[TimeStamp, str]]], - ): + def __init__(self, *, id: Optional[int] = None, external_id: Optional[str] = None, datapoints: List[DataPoint]): self.id = id self.external_id = external_id self.datapoints = datapoints diff --git a/pyproject.toml b/pyproject.toml index 92e2aaa3..b85cd614 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cognite-extractor-utils" -version = "5.4.1" +version = "5.4.2" description = "Utilities for easier development of extractors for CDF" authors = ["Mathias Lohne "] license = "Apache-2.0"