From c23a41c2e320584a298db9f29f08789768c32479 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Mon, 29 Jan 2024 11:07:26 +0100 Subject: [PATCH] fix linter errors (#282) --- .../document_stores/qdrant/filters.py | 24 +++++---- integrations/qdrant/tests/test_filters.py | 21 +++----- .../qdrant/tests/test_legacy_filters.py | 51 +++++++------------ 3 files changed, 39 insertions(+), 57 deletions(-) diff --git a/integrations/qdrant/src/haystack_integrations/document_stores/qdrant/filters.py b/integrations/qdrant/src/haystack_integrations/document_stores/qdrant/filters.py index 21e29e570..77d800853 100644 --- a/integrations/qdrant/src/haystack_integrations/document_stores/qdrant/filters.py +++ b/integrations/qdrant/src/haystack_integrations/document_stores/qdrant/filters.py @@ -113,9 +113,11 @@ def _build_in_condition(self, key: str, value: List[models.ValueVariants]) -> mo raise FilterError(msg) return models.Filter( should=[ - models.FieldCondition(key=key, match=models.MatchText(text=item)) - if isinstance(item, str) and " " not in item - else models.FieldCondition(key=key, match=models.MatchValue(value=item)) + ( + models.FieldCondition(key=key, match=models.MatchText(text=item)) + if isinstance(item, str) and " " not in item + else models.FieldCondition(key=key, match=models.MatchValue(value=item)) + ) for item in value ] ) @@ -123,9 +125,11 @@ def _build_in_condition(self, key: str, value: List[models.ValueVariants]) -> mo def _build_ne_condition(self, key: str, value: models.ValueVariants) -> models.Condition: return models.Filter( must_not=[ - models.FieldCondition(key=key, match=models.MatchText(text=value)) - if isinstance(value, str) and " " not in value - else models.FieldCondition(key=key, match=models.MatchValue(value=value)) + ( + models.FieldCondition(key=key, match=models.MatchText(text=value)) + if isinstance(value, str) and " " not in value + else models.FieldCondition(key=key, match=models.MatchValue(value=value)) + ) ] ) @@ -135,9 +139,11 @@ def _build_nin_condition(self, key: str, value: List[models.ValueVariants]) -> m raise FilterError(msg) return models.Filter( must_not=[ - models.FieldCondition(key=key, match=models.MatchText(text=item)) - if isinstance(item, str) and " " not in item - else models.FieldCondition(key=key, match=models.MatchValue(value=item)) + ( + models.FieldCondition(key=key, match=models.MatchText(text=item)) + if isinstance(item, str) and " " not in item + else models.FieldCondition(key=key, match=models.MatchValue(value=item)) + ) for item in value ] ) diff --git a/integrations/qdrant/tests/test_filters.py b/integrations/qdrant/tests/test_filters.py index 848d799e4..74bac76ad 100644 --- a/integrations/qdrant/tests/test_filters.py +++ b/integrations/qdrant/tests/test_filters.py @@ -86,29 +86,22 @@ def test_comparison_less_than_equal_with_none(self, document_store, filterable_d # ======== ========================== ======== @pytest.mark.skip(reason="Qdrant doesn't support comparision with dataframe") - def test_comparison_equal_with_dataframe(self, document_store, filterable_docs): - ... + def test_comparison_equal_with_dataframe(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Qdrant doesn't support comparision with dataframe") - def test_comparison_not_equal_with_dataframe(self, document_store, filterable_docs): - ... + def test_comparison_not_equal_with_dataframe(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Qdrant doesn't support comparision with Dates") - def test_comparison_greater_than_with_iso_date(self, document_store, filterable_docs): - ... + def test_comparison_greater_than_with_iso_date(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Qdrant doesn't support comparision with Dates") - def test_comparison_greater_than_equal_with_iso_date(self, document_store, filterable_docs): - ... + def test_comparison_greater_than_equal_with_iso_date(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Qdrant doesn't support comparision with Dates") - def test_comparison_less_than_with_iso_date(self, document_store, filterable_docs): - ... + def test_comparison_less_than_with_iso_date(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Qdrant doesn't support comparision with Dates") - def test_comparison_less_than_equal_with_iso_date(self, document_store, filterable_docs): - ... + def test_comparison_less_than_equal_with_iso_date(self, document_store, filterable_docs): ... @pytest.mark.skip(reason="Cannot distinguish errors yet") - def test_missing_top_level_operator_key(self, document_store, filterable_docs): - ... + def test_missing_top_level_operator_key(self, document_store, filterable_docs): ... diff --git a/integrations/qdrant/tests/test_legacy_filters.py b/integrations/qdrant/tests/test_legacy_filters.py index ff01c3971..60f1fad2b 100644 --- a/integrations/qdrant/tests/test_legacy_filters.py +++ b/integrations/qdrant/tests/test_legacy_filters.py @@ -44,8 +44,7 @@ def test_filter_simple_metadata_value(self, document_store: DocumentStore, filte self.assert_documents_are_equal(result, [doc for doc in filterable_docs if doc.meta.get("page") == "100"]) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_filter_document_dataframe(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_filter_document_dataframe(self, document_store: DocumentStore, filterable_docs: List[Document]): ... def test_eq_filter_explicit(self, document_store: DocumentStore, filterable_docs: List[Document]): document_store.write_documents(filterable_docs) @@ -58,12 +57,10 @@ def test_eq_filter_implicit(self, document_store: DocumentStore, filterable_docs self.assert_documents_are_equal(result, [doc for doc in filterable_docs if doc.meta.get("page") == "100"]) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_eq_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_eq_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_eq_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_eq_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsNotEqualTest @@ -73,12 +70,10 @@ def test_ne_filter(self, document_store: DocumentStore, filterable_docs: List[Do self.assert_documents_are_equal(result, [doc for doc in filterable_docs if doc.meta.get("page") != "100"]) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_ne_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_ne_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_ne_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_ne_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsInTest @@ -122,22 +117,18 @@ def test_in_filter_implicit(self, document_store: DocumentStore, filterable_docs ) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_in_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_in_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_in_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_in_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsNotInTest @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_nin_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_nin_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_nin_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_nin_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... def test_nin_filter(self, document_store: DocumentStore, filterable_docs: List[Document]): document_store.write_documents(filterable_docs) @@ -163,12 +154,10 @@ def test_gt_filter_non_numeric(self, document_store: DocumentStore, filterable_d document_store.filter_documents(filters={"meta.page": {"$gt": "100"}}) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_gt_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_gt_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_gt_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_gt_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsGreaterThanEqualTest @@ -186,12 +175,10 @@ def test_gte_filter_non_numeric(self, document_store: DocumentStore, filterable_ document_store.filter_documents(filters={"meta.page": {"$gte": "100"}}) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_gte_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_gte_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_gte_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_gte_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsLessThanTest @@ -209,12 +196,10 @@ def test_lt_filter_non_numeric(self, document_store: DocumentStore, filterable_d document_store.filter_documents(filters={"meta.page": {"$lt": "100"}}) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_lt_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_lt_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_lt_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_lt_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsLessThanEqualTest @@ -232,12 +217,10 @@ def test_lte_filter_non_numeric(self, document_store: DocumentStore, filterable_ document_store.filter_documents(filters={"meta.page": {"$lte": "100"}}) @pytest.mark.skip(reason="Dataframe filtering is not supported in Qdrant") - def test_lte_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_lte_filter_table(self, document_store: DocumentStore, filterable_docs: List[Document]): ... @pytest.mark.skip(reason="Embedding filtering is not supported in Qdrant") - def test_lte_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): - ... + def test_lte_filter_embedding(self, document_store: DocumentStore, filterable_docs: List[Document]): ... # LegacyFilterDocumentsSimpleLogicalTest