Skip to content

Commit f103bbe

Browse files
committed
fix python 3.9 compatibility issues
1 parent 79a4f24 commit f103bbe

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

bigframes/session/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from collections import abc
2020
import datetime
21+
import fnmatch
22+
import inspect
2123
import logging
2224
import os
2325
import secrets
@@ -1349,8 +1351,19 @@ def _check_file_size(self, filepath: str):
13491351
client = storage.Client()
13501352
bucket = client.bucket(bucket_name)
13511353

1352-
matching_blobs = bucket.list_blobs(match_glob=blob_path)
1353-
file_size = sum(blob.size for blob in matching_blobs)
1354+
list_blobs_params = inspect.signature(bucket.list_blobs).parameters
1355+
if "match_glob" in list_blobs_params:
1356+
# Modern, efficient method for new library versions
1357+
matching_blobs = bucket.list_blobs(match_glob=blob_path)
1358+
file_size = sum(blob.size for blob in matching_blobs)
1359+
else:
1360+
# Fallback method for older library versions
1361+
prefix = blob_path.split("*", 1)[0]
1362+
all_blobs = bucket.list_blobs(prefix=prefix)
1363+
matching_blobs = [
1364+
blob for blob in all_blobs if fnmatch.fnmatch(blob.name, blob_path)
1365+
]
1366+
file_size = sum(blob.size for blob in matching_blobs)
13541367
elif os.path.exists(filepath): # local file path
13551368
file_size = os.path.getsize(filepath)
13561369
else:

tests/system/small/test_session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,15 @@ def test_read_csv_for_gcs_wildcard_path(session, df_and_gcs_csv):
12731273
# Convert default pandas dtypes to match BigQuery DataFrames dtypes.
12741274
# Also, `expand=True` is needed to read from wildcard paths. See details:
12751275
# https://github.com/fsspec/gcsfs/issues/616,
1276+
if not pd.__version__.startswith("1."):
1277+
storage_options = {"expand": True}
1278+
else:
1279+
storage_options = None
12761280
pd_df = session.read_csv(
12771281
path,
12781282
index_col=index_col,
12791283
dtype=scalars_pandas_df.dtypes.to_dict(),
1280-
storage_options={"expand": True},
1284+
storage_options=storage_options,
12811285
)
12821286

12831287
assert bf_df.shape == pd_df.shape

0 commit comments

Comments
 (0)