Skip to content

Commit

Permalink
Fix lint/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steinitzu committed Dec 6, 2024
1 parent 10e0770 commit 76463d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions dlt/extract/incremental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def __str__(self) -> str:
f" {self.last_value_func}"
)

def _make_transformer(self, cls: Type[IncrementalTransform]) -> IncrementalTransform:
def _make_or_get_transformer(self, cls: Type[IncrementalTransform]) -> IncrementalTransform:
if transformer := self._transformers.get(cls):
return transformer
transformer = self._transformers[cls] = cls(
Expand All @@ -540,11 +540,11 @@ def _get_transformer(self, items: TDataItems) -> IncrementalTransform:
# Assume list is all of the same type
for item in items if isinstance(items, list) else [items]:
if is_arrow_item(item):
return self._make_transformer(ArrowIncremental)
return self._make_or_get_transformer(ArrowIncremental)
elif pandas is not None and isinstance(item, pandas.DataFrame):
return self._make_transformer(ArrowIncremental)
return self._make_transformer(JsonIncremental)
return self._make_transformer(JsonIncremental)
return self._make_or_get_transformer(ArrowIncremental)
return self._make_or_get_transformer(JsonIncremental)
return self._make_or_get_transformer(JsonIncremental)

def __call__(self, rows: TDataItems, meta: Any = None) -> Optional[TDataItems]:
if rows is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/extract/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -3864,7 +3864,7 @@ def test_start_range_open(item_type: TestDataItemFormat, last_value_func: Any) -
expected_items = list(range(6, 12))
order_dir = "ASC"
elif last_value_func == min:
data_range = reversed(data_range)
data_range = reversed(data_range) # type: ignore[call-overload]
initial_value = 5
# Only items lower than inital extracted
expected_items = list(reversed(range(1, 5)))
Expand Down
9 changes: 5 additions & 4 deletions tests/load/sources/sql_database/test_sql_database_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dlt.common.utils import uniq_id

from dlt.extract.exceptions import ResourceExtractionError
from dlt.extract.incremental.transform import JsonIncremental, ArrowIncremental
from dlt.sources import DltResource

from tests.pipeline.utils import (
Expand Down Expand Up @@ -831,8 +832,8 @@ def _assert_incremental(item):
else:
assert _r.incremental.primary_key == ["id"]
assert _r.incremental._incremental.primary_key == ["id"]
assert _r.incremental._incremental._transformers["json"].primary_key == ["id"]
assert _r.incremental._incremental._transformers["arrow"].primary_key == ["id"]
assert _r.incremental._incremental._make_or_get_transformer(JsonIncremental).primary_key == ["id"]
assert _r.incremental._incremental._make_or_get_transformer(ArrowIncremental).primary_key == ["id"]
return item

pipeline = make_pipeline("duckdb")
Expand All @@ -841,8 +842,8 @@ def _assert_incremental(item):

assert resource.incremental.primary_key == ["id"]
assert resource.incremental._incremental.primary_key == ["id"]
assert resource.incremental._incremental._transformers["json"].primary_key == ["id"]
assert resource.incremental._incremental._transformers["arrow"].primary_key == ["id"]
assert resource.incremental._incremental._make_or_get_transformer(JsonIncremental).primary_key == ["id"]
assert resource.incremental._incremental._make_or_get_transformer(ArrowIncremental).primary_key == ["id"]


@pytest.mark.parametrize("backend", ["sqlalchemy", "pyarrow", "pandas", "connectorx"])
Expand Down

0 comments on commit 76463d5

Please sign in to comment.