Commit cbaebf8

benny-dou <60535774+benny-dou@users.noreply.github.com>
2026-04-28 07:49:57
fix(danmu): handle non-bytes response from R2
1 parent a971160
Changed files (1)
src
danmu
src/danmu/r2.py
@@ -93,11 +93,13 @@ async def query_r2_for_date(date: str, r2_key: str, qtype: str) -> pd.DataFrame:
 
     async def r2_to_dataframe(r2_key: str) -> pd.DataFrame:
         logger.debug(f"Query {qtype} from R2: {date}")
-        parquet: bytes = await get_cf_r2(r2_key, rformat="bytes", silent=True)  # ty:ignore[invalid-assignment]
-        df = pd.read_parquet(BytesIO(parquet)).drop_duplicates()
-        path.parent.mkdir(parents=True, exist_ok=True)
-        df.to_parquet(path, index=False, compression="brotli")
-        return df
+        parquet = await get_cf_r2(r2_key, rformat="bytes", silent=True)
+        if isinstance(parquet, bytes):
+            df = pd.read_parquet(BytesIO(parquet)).drop_duplicates()
+            path.parent.mkdir(parents=True, exist_ok=True)
+            df.to_parquet(path, index=False, compression="brotli")
+            return df
+        return pd.DataFrame()
 
     this_year = nowdt(TZ).strftime("%Y")
     this_month = nowdt(TZ).strftime("%Y-%m")