Skip to content

Commit 1485af3

Browse files
authored
Merge pull request #46 from sanders41/static
Refactored _load_documents_from_file to a static method
2 parents 8dbb635 + 88b3c02 commit 1485af3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

meilisearch_python_async/index.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ async def add_documents_from_file(
479479
MeilisearchCommunicationError: If there was an error communicating with the server.
480480
MeilisearchApiError: If the MeiliSearch API returned an error.
481481
"""
482-
documents = await self._load_documents_from_file(file_path)
482+
documents = await Index._load_documents_from_file(file_path)
483483

484484
return await self.add_documents(documents, primary_key=primary_key)
485485

@@ -509,7 +509,7 @@ async def add_documents_from_file_auto_batch(
509509
MeiliSearchApiError: If the MeiliSearch API returned an error.
510510
PayloadTooLarge: If the largest document is larget than the max_payload_size
511511
"""
512-
documents = await self._load_documents_from_file(file_path)
512+
documents = await Index._load_documents_from_file(file_path)
513513

514514
update_ids = []
515515
async for batch in Index._generate_auto_batches(documents, max_payload_size):
@@ -538,7 +538,7 @@ async def add_documents_from_file_in_batches(
538538
MeiliSearchCommunicationError: If there was an error communicating with the server.
539539
MeiliSearchApiError: If the MeiliSearch API returned an error.
540540
"""
541-
documents = await self._load_documents_from_file(file_path)
541+
documents = await Index._load_documents_from_file(file_path)
542542

543543
return await self.add_documents_in_batches(
544544
documents, batch_size=batch_size, primary_key=primary_key
@@ -647,7 +647,7 @@ async def update_documents_from_file(
647647
MeilisearchCommunicationError: If there was an error communicating with the server.
648648
MeilisearchApiError: If the MeiliSearch API returned an error.
649649
"""
650-
documents = await self._load_documents_from_file(file_path)
650+
documents = await Index._load_documents_from_file(file_path)
651651

652652
return await self.update_documents(documents, primary_key=primary_key)
653653

@@ -676,7 +676,7 @@ async def update_documents_from_file_auto_batch(
676676
MeilisearchCommunicationError: If there was an error communicating with the server.
677677
MeilisearchApiError: If the MeiliSearch API returned an error.
678678
"""
679-
documents = await self._load_documents_from_file(file_path)
679+
documents = await Index._load_documents_from_file(file_path)
680680

681681
update_ids = []
682682
async for batch in Index._generate_auto_batches(documents, max_payload_size):
@@ -704,7 +704,7 @@ async def update_documents_from_file_in_batches(
704704
MeilisearchCommunicationError: If there was an error communicating with the server.
705705
MeilisearchApiError: If the MeiliSearch API returned an error.
706706
"""
707-
documents = await self._load_documents_from_file(file_path)
707+
documents = await Index._load_documents_from_file(file_path)
708708

709709
return await self.update_documents_in_batches(
710710
documents, batch_size=batch_size, primary_key=primary_key
@@ -1220,7 +1220,8 @@ def _iso_to_date_time(iso_date: datetime | str | None) -> datetime | None:
12201220
reduced = f"{split[0]}.{split[1][:-reduce]}Z"
12211221
return datetime.strptime(reduced, "%Y-%m-%dT%H:%M:%S.%fZ")
12221222

1223-
async def _load_documents_from_file(self, file_path: Path | str) -> list[dict]:
1223+
@staticmethod
1224+
async def _load_documents_from_file(file_path: Path | str) -> list[dict]:
12241225
if isinstance(file_path, str):
12251226
file_path = Path(file_path)
12261227

0 commit comments

Comments
 (0)