To solve
ImportError: cannot import name 'types' from 'geoarrow' (unknown location),
install geoarrow-types.
ibis may also need geoarrow-cto work with geoparquet now.
| import streamlit as st | |
| import os | |
| #os.environ["OPENAI_API_KEY"] = st.secrets['OPENAI_API_KEY'] # for gpt | |
| os.environ["OPENAI_API_KEY"] = st.secrets['LITELLM_KEY'] # for litellm | |
| from pydantic import BaseModel, Field | |
| class SQLResponse(BaseModel): | |
| """Defines the structure for SQL response.""" |
| parquet = "https://espm-157-f24.github.io/spatial-carl-amanda-tyler/new_haven_stats.parquet" | |
| # create sharable low-level connection, see: https://github.com/Mause/duckdb_engine | |
| import sqlalchemy | |
| eng = sqlalchemy.create_engine("duckdb:///:memory:") | |
| # ibis can talk to this connection and create the VIEW | |
| import ibis | |
| con = ibis.duckdb.from_connection(eng.raw_connection()) |
| %%time | |
| import ibis | |
| from ibis import _ | |
| con = ibis.duckdb.connect() | |
| endpoint="rook-ceph-rgw-nautiluss3.rook" | |
| query= f''' | |
| CREATE OR REPLACE SECRET secret2 ( |
| import ibis | |
| from ibis import _ | |
| con = ibis.duckdb.connect() | |
| # example query, could be anything | |
| subset = (gbif | |
| .filter(_["class"] == "Aves") | |
| .rename(hex = "h8") | |
| .group_by(_.hex) | |
| .agg(n = _.count()) |
To solve
ImportError: cannot import name 'types' from 'geoarrow' (unknown location),
install geoarrow-types.
ibis may also need geoarrow-cto work with geoparquet now.
| import os | |
| from langchain_openai import ChatOpenAI | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from langchain_core.runnables import ConfigurableField | |
| from langchain_core.tools import tool | |
| from langchain.agents import create_tool_calling_agent, AgentExecutor | |
| @tool | |
| def multiply(x: float, y: float) -> float: | |
| """Multiply 'x' times 'y'.""" | |
| return x * y |
| import ibis | |
| con = ibis.duckdb.connect() | |
| con.raw_sql(f''' | |
| CREATE OR REPLACE SECRET secret ( | |
| TYPE S3, | |
| ENDPOINT 'sdsc.osn.xsede.org', | |
| URL_STYLE 'path' | |
| ); |
| import ibis | |
| from ibis import _ | |
| con = ibis.duckdb.connect(extensions=["spatial"]) | |
| ## Read a geospatial file other than parquet (via GDAL) | |
| rivers_geojson = "https://data.source.coop/cboettig/us-rivers/nhd_flowline_national.geojson" | |
| rivers = con.read_geo(rivers_geojson) | |
| ## Read geoparquet |
| conn.sql(''' | |
| SELECT * | |
| FROM information_schema.columns | |
| WHERE table_name = 'families'; | |
| ''' | |
| ) |
| # Be sure to put a copy of the license file in "$HOME/gurobi.lic" for this to work!! | |
| # Download the release | |
| wget https://packages.gurobi.com/11.0/gurobi11.0.1_linux64.tar.gz # or path to most recent linux_64 download from https://www.gurobi.com/downloads/gurobi-software/ | |
| # extract: | |
| tar -xvf gurobi*_linux64.tar.gz | |
| # Set environmental variables |