Giter Club home page Giter Club logo

Comments (7)

long2ice avatar long2ice commented on August 15, 2024

No, what's the relation between asynch and pandas? What's the meaning to select directly to dataframe?

from asynch.

ghuname avatar ghuname commented on August 15, 2024

Well, we are talking here about clickhouse database, and how to access it asynchronously.
Most of the time, we will selecting data from database.
When you are selecting data from database you need some complex structure to hold the result.
If we are talking about python, pandas dataframe has no alternative for such purpose, if you need to further do something with the data (data wrangling, machine learning...).

At the moment I am using clickhouse_driver and DB API connection and pandas.read_sql function (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_sql.html).

As aioch doesn't have DB API connection I am kind of stuck with that approach.
I will try to do the same with your asynch driver. I hope it will work.

from asynch.

long2ice avatar long2ice commented on August 15, 2024

Well, so did you try it? I never use pandas, and asynch also support DB API.

from asynch.

ghuname avatar ghuname commented on August 15, 2024

I tried this:

async def main():
    conn = await connect(
        host="127.0.0.1",
        port=9001,
        database="default",
    )

    async with conn.cursor() as cursor:
        await cursor.execute("SELECT 1")
        ret = cursor.fetchone()
        print(ret)

I got (1,) as a result, but where are column types? As I can see you are using with_column_types=True in response = await execute(query, args=args, with_column_types=True, **execute_kwargs), but you are not returning them.

Anyway I hoped that the following will work, but it doesn't:

import asyncio
from asynch import connect
import pandas as pd
from jinjasql import JinjaSql

async def main():
    conn = await connect(
        host="127.0.0.1",
        port=9001,
        database="default",
    )

    jsql = JinjaSql(param_style='pyformat')

    sql_templ = 'select 1'
    params = {}

    query, bind_params = jsql.prepare_query(sql_templ, params)
    df = pd.read_sql_query(query, conn, params=bind_params) # I tried df = await pd.read_sql(...) but it hasn't worked

    print(df)

asyncio.run(main())
RuntimeWarning: coroutine 'Cursor.execute' was never awaited
  cur.execute(*args, **kwargs)

Looks like you should create/delete the cursor on the fly in the background for such usage.

from asynch.

ghuname avatar ghuname commented on August 15, 2024

@long2ice can you please comment my findings?

from asynch.

long2ice avatar long2ice commented on August 15, 2024

Does pandas support asyncio?

from asynch.

ghuname avatar ghuname commented on August 15, 2024

No

from asynch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.