Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle list like input objects in weavaite's 'create_or_replace_document_objects' hook method #36475

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions airflow/providers/weaviate/hooks/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import json
import warnings
from functools import cached_property
from typing import TYPE_CHECKING, Any, Dict, List, cast
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, cast

import requests
import weaviate.exceptions
Expand All @@ -36,7 +36,7 @@
from airflow.hooks.base import BaseHook

if TYPE_CHECKING:
from typing import Callable, Collection, Literal, Sequence
from typing import Callable, Collection, Literal

import pandas as pd
from weaviate.types import UUID
Expand Down Expand Up @@ -974,10 +974,10 @@ def create_or_replace_document_objects(
if len(data) == 0:
return []

if isinstance(data, list) and isinstance(data[0], dict):
if isinstance(data, Sequence) and isinstance(data[0], dict):
# This is done to narrow the type to List[Dict[str, Any].
data = pd.json_normalize(cast(List[Dict[str, Any]], data))
elif isinstance(data, list) and isinstance(data[0], pd.DataFrame):
elif isinstance(data, Sequence) and isinstance(data[0], pd.DataFrame):
# This is done to narrow the type to List[pd.DataFrame].
data = pd.concat(cast(List[pd.DataFrame], data), ignore_index=True)
else:
Expand Down