Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide convenient way for loading query results into a data frame #83

Open
kebab-mai-haddi opened this issue Jun 17, 2019 · 16 comments
Open

Comments

@kebab-mai-haddi
Copy link

I want to create a data frame from hive using Presto. I am done with it but with one exception: there are empty strings in my data which would be NaN if the corresponding CSV file is read using Pandas (pd.read_csv()).

I read several documentations but none address this issue.

My code for creating a data frame from Presto is pretty straightforward:

def get_pandas_dataframe(self, hql, parameters=None):
        if not self.airflow_conn_reqd:
            import pandas
            cursor = self.presto_client.cursor()
            try:
                cursor.execute(self._strip_sql(hql), parameters)
                data = cursor.fetchall()
            except DatabaseError as e:
                raise PrestoException(self._get_pretty_exception_message(e))
            column_descriptions = cursor.description
            if data:
                df = pandas.DataFrame(data)
                df.columns = [c[0] for c in column_descriptions]
            else:
                df = pandas.DataFrame()
            return df
        else:
            return(
                self.get_pandas_df(query)
            )

As you can see, there exists a line df = pandas.DataFrame(data). Now, I read the documentation of pandas.DataFrame() and could not find any method of keeping keep_default_na to True so that the empty string '' are treated as NaN as Pandas would treat them.

@ggreg
Copy link
Contributor

ggreg commented Jun 25, 2019

@avisrivastava254084 can you describe the schema of the tables you are reading and provide an example with rows from this table? In other words, could you describe the data that you're querying from Presto and the expected values in the pandas Dataframe.

@kebab-mai-haddi
Copy link
Author

kebab-mai-haddi commented Jun 26, 2019

@ggreg sorry for responding late, can we close this issue and instead discuss the main topic "Creating pandas data frame in presto client" instead? This issue

@ggreg
Copy link
Contributor

ggreg commented Jun 26, 2019

This is the repository for the Presto Python client. The other issue is in the Presto engine codebase.

@mbasmanova
Copy link

@avisrivastava254084 Aviral, prestodb/presto-python-client (this repo) is a proper place for Python client enhancements. The other repo, prestodb/presto, contains code for the Presto itself. Are you thinking of making changes in the presto client or presto code?

@kebab-mai-haddi
Copy link
Author

kebab-mai-haddi commented Jun 26, 2019 via email

@mbasmanova
Copy link

@avisrivastava254084 Makes sense to me.

@mbasmanova mbasmanova changed the title How to give keep_default_na or similar function of pd.read_csv while creating a dataframe using pd.Dataframe(data)? Provide convenient way for loading query results into a data frame Jun 26, 2019
@ggreg
Copy link
Contributor

ggreg commented Jun 26, 2019

I'd like to avoid introducing a dependency to pandas. I was thinking of providing an interface to return the data in the right format.

@kebab-mai-haddi
Copy link
Author

@ggreg
I am telling you from my own experience, this library is in use and giving the data scientists the ability to create data frames is needed. Imagine being a data scientist and having rightful abstractions over S3(where data is stored), Hive(where meta is stored) and SQL(Presto, which is an engine).

Not only Pandas, we should also think of implementing the same for pyspark i.e. creating Spark data frame from Presto.

But I would like your input on this and your thought process, maybe I am having a bias.

@ggreg
Copy link
Contributor

ggreg commented Jul 18, 2019

@avisrivastava254084 i appreciate the value of support this. My main concern is to not conflate too many things into the Presto Python client library.

What do you think about providing these features in another library, called presto-python-common (i welcome better names too :) )?

@kebab-mai-haddi
Copy link
Author

kebab-mai-haddi commented Jul 19, 2019 via email

@ggreg
Copy link
Contributor

ggreg commented Jul 22, 2019

I'm preparing the repo so it follows the requirements for an open source repository and allow to easily contribute new modules. I'll ping when it is ready.

Meanwhile how would we call the module to manipulate dataframes? Should we just call it prestodb.dataframe and provide a get(sql, **kwargs) -> pandas.DataFrame function?

@kebab-mai-haddi
Copy link
Author

kebab-mai-haddi commented Jul 23, 2019 via email

@adeora
Copy link

adeora commented Feb 21, 2020

Is there any progress on this? It would be incredibly helpful for my use cases.

@kebab-mai-haddi
Copy link
Author

@ggreg any update? I am still up for this.

@mbasmanova
Copy link

@ggreg no longer works on the project. @mayankgarg1990 Do you know what might help here?

@kebab-mai-haddi
Copy link
Author

Thanks @mbasmanova !

@mayankgarg1990
As you can see, there is clearly a need for this. Let me know if you guys need some context and if time is an issue, we can fasten this up on a call or something.

hi at aviralsrivastava dot com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants