Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 24 additions & 12 deletions buckaroo/serialization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from typing import Dict, Any, List, Tuple
from pandas._libs.tslibs import timezones
from pandas.core.dtypes.dtypes import DatetimeTZDtype
from fastparquet import json as fp_json
try:
from fastparquet import json as fp_json
HAS_FASTPARQUET = True
except ImportError:
fp_json = None
HAS_FASTPARQUET = False
import logging

from buckaroo.df_util import old_col_new_col, to_chars
Expand Down Expand Up @@ -128,19 +133,20 @@ def pd_to_obj(df:pd.DataFrame) -> Dict[str, Any]:
pass


class MyJsonImpl(fp_json.BaseImpl):
def __init__(self):
pass
#for some reason the following line causes errors, so I have to reimport ujson_dumps
# from pandas._libs.json import ujson_dumps
# self.dumps = ujson_dumps
if HAS_FASTPARQUET:
class MyJsonImpl(fp_json.BaseImpl):
def __init__(self):
pass
#for some reason the following line causes errors, so I have to reimport ujson_dumps
# from pandas._libs.json import ujson_dumps
# self.dumps = ujson_dumps

def dumps(self, data):
from pandas._libs.json import ujson_dumps
return ujson_dumps(data, default_handler=str).encode("utf-8")
def dumps(self, data):
from pandas._libs.json import ujson_dumps
return ujson_dumps(data, default_handler=str).encode("utf-8")

def loads(self, s):
return self.api.loads(s)
def loads(self, s):
return self.api.loads(s)

def get_multiindex_to_cols_sers(index) -> List[Tuple[str, Any]]: #pd.Series[Any]
if not isinstance(index, pd.MultiIndex):
Expand Down Expand Up @@ -168,6 +174,12 @@ def prepare_df_for_serialization(df:pd.DataFrame) -> pd.DataFrame:
return df2

def to_parquet(df):
if not HAS_FASTPARQUET:
raise ImportError(
"fastparquet is required for parquet serialization but is not installed. "
"Install it with: pip install fastparquet"
)

data: BytesIO = BytesIO()

# data.close doesn't work in pyodide, so we make close a no-op
Expand Down
9 changes: 8 additions & 1 deletion docs/example-notebooks/marimo-wasm/buckaroo_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ async def _():

if "pyodide" in sys.modules:
import micropip
await micropip.install("buckaroo", keep_going=True)
# Install native WASM packages from Pyodide's bundle first
# (Pyodide 0.27.7 bundles fastparquet 2024.5.0, pyarrow, numpy, etc.)
await micropip.install("fastparquet")
await micropip.install("pyarrow")
# Install buckaroo's pure-python deps, then buckaroo itself with deps=False
# to skip dependency resolution (which fails on non-pure-Python deps)
await micropip.install(["anywidget", "graphlib_backport", "cloudpickle"])
await micropip.install("buckaroo", deps=False)

import buckaroo
from buckaroo import BuckarooWidget, BuckarooInfiniteWidget
Expand Down
Empty file.
Loading
Loading