Skip to content

Commit b510e21

Browse files
authored
Remove explicit tqdm dependency (#448)
## Problem We want to minimize the number of required dependencies we have, and tqdm is non-essential. Moreover, common notebook environments like Google Colab will already have tqdm loaded even if we do not declare this an explicit dependency. ## Solution Instead of having a specific dependency on tqdm, we want to detect and use it if it is available in the environment. Otherwise just noop with a stub implementation of our own. ## Type of Change - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] This change requires a documentation update
1 parent 9b4a2a1 commit b510e21

File tree

8 files changed

+64
-31
lines changed

8 files changed

+64
-31
lines changed

pinecone/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
.. include:: ../README.md
33
"""
44

5-
import warnings
6-
from tqdm import TqdmExperimentalWarning
7-
8-
warnings.filterwarnings("ignore", category=TqdmExperimentalWarning)
9-
105
from .deprecated_plugins import check_for_deprecated_plugins
116
from .deprecation_warnings import *
127
from .config import *

pinecone/data/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tqdm.autonotebook import tqdm
1+
from pinecone.utils.tqdm import tqdm
22

33
import logging
44
import json

pinecone/data/index_asyncio.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from tqdm.autonotebook import tqdm
1+
from pinecone.utils.tqdm import tqdm
2+
23

34
import logging
45
import asyncio

pinecone/grpc/index_grpc.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from google.protobuf import json_format
55

6-
from tqdm.autonotebook import tqdm
6+
from pinecone.utils.tqdm import tqdm
77
from concurrent.futures import as_completed, Future
88

99

@@ -207,7 +207,9 @@ def upsert_from_dataframe(
207207
results = [
208208
async_result.result()
209209
for async_result in tqdm(
210-
cast_results, disable=not show_progress, desc="collecting async responses"
210+
iterable=cast_results,
211+
disable=not show_progress,
212+
desc="collecting async responses",
211213
)
212214
]
213215

pinecone/utils/tqdm.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
try:
2+
# Use the notebook-friendly auto selection if tqdm is installed.
3+
from tqdm.auto import tqdm
4+
except ImportError:
5+
# Fallback: define a dummy tqdm that supports the same interface.
6+
class tqdm: # type: ignore
7+
def __init__(self, iterable=None, total=None, desc="", **kwargs):
8+
self.iterable = iterable
9+
self.total = total
10+
self.desc = desc
11+
# You can store additional kwargs if needed
12+
13+
def __iter__(self):
14+
# Just iterate over the underlying iterable
15+
for item in self.iterable:
16+
yield item
17+
18+
def update(self, n=1):
19+
# No-op: This stub doesn't track progress
20+
pass
21+
22+
def __enter__(self):
23+
# Allow use as a context manager
24+
return self
25+
26+
def __exit__(self, exc_type, exc_value, traceback):
27+
# Nothing to cleanup
28+
pass

poetry.lock

+1-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ urllib3 = [
3838
{ version = ">=1.26.0", python = ">=3.8,<3.12" },
3939
{ version = ">=1.26.5", python = "^3.12" }
4040
]
41-
tqdm = ">=4.64.1"
4241
# certifi does not follow semver. Should always be
4342
# on latest but setting a broad range to have maximum
4443
# compatibility with libraries that may pin version.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pandas as pd
2+
from pinecone.data import _Index
3+
from ..helpers import embedding_values, random_string
4+
5+
6+
class TestUpsertFromDataFrame:
7+
def test_upsert_from_dataframe(self, idx: _Index):
8+
# Create sample data for testing.
9+
data = {
10+
"id": ["1", "2", "3"],
11+
"values": [embedding_values(), embedding_values(), embedding_values()],
12+
"sparse_values": [
13+
{"indices": [1], "values": [0.234]},
14+
{"indices": [2], "values": [0.432]},
15+
{"indices": [3], "values": [0.543]},
16+
],
17+
"metadata": [
18+
{"source": "generated", "quality": "high"},
19+
{"source": "generated", "quality": "medium"},
20+
{"source": "generated", "quality": "low"},
21+
],
22+
}
23+
24+
# Create the DataFrame
25+
df = pd.DataFrame(data)
26+
27+
ns = random_string(10)
28+
idx.upsert_from_dataframe(df=df, namespace=ns)

0 commit comments

Comments
 (0)