docs.sheetjs.com/tests/math/polars.sh

52 lines
1.5 KiB
Bash
Raw Normal View History

2026-01-25 20:10:48 +00:00
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/math/pandas
OS=$(uname -s)
cd /tmp
rm -rf sheetjs-polars
mkdir sheetjs-polars
cd sheetjs-polars
curl -LO https://duktape.org/duktape-2.7.0.tar.xz
tar -xJf duktape-2.7.0.tar.xz
cd duktape-2.7.0
make -f Makefile.sharedlibrary
cd ..
OS="$(uname -s)"
case "$OS" in
Darwin) LIB_NAME="libduktape.207.20700.so" ;;
Linux) LIB_NAME="libduktape.so.207.20700" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
cp "duktape-2.7.0/$LIB_NAME" .
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/shim.min.js
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
curl -LO https://docs.sheetjs.com/pres.numbers
curl -LO https://docs.sheetjs.com/pandas/sheetjs.py
curl -LO https://docs.sheetjs.com/pandas/SheetJSPandas.py
sed "s#libduktape.207.20700.so#$LIB_NAME#g" sheetjs.py > sheetjs.py.tmp
mv sheetjs.py.tmp sheetjs.py
sed "s#from pandas import read_csv#from polars import read_csv#g" sheetjs.py > sheetjs.py.tmp
mv sheetjs.py.tmp sheetjs.py
sed 's#json = df.to_json(orient="records")#json = df.write_json()#g' sheetjs.py > sheetjs.py.tmp
mv sheetjs.py.tmp sheetjs.py
sed 's#print(df.info())#print(df)#g' SheetJSPandas.py > SheetJSPandas.py.tmp
mv SheetJSPandas.py.tmp SheetJSPandas.py
sed 's#SheetJSPandas.xlsb#SheetJSPolars.xlsb#g' SheetJSPandas.py > SheetJSPandas.py.tmp
mv SheetJSPandas.py.tmp SheetJSPandas.py
python3 SheetJSPandas.py pres.numbers || python SheetJSPandas.py pres.numbers
npx -y xlsx-cli SheetJSPolars.xlsb