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

Raise error if dataframe is empty #1238

Merged
merged 10 commits into from
Nov 16, 2022
Merged

Raise error if dataframe is empty #1238

merged 10 commits into from
Nov 16, 2022

Conversation

pankajastro
Copy link
Contributor

@pankajastro pankajastro commented Nov 11, 2022

Description

closes: #810

What is the current behavior?

In case of an empty dataframe the data frame operator throws an SQL syntax error.

What is the new behavior?

If the dataframe is empty then raise an error

Does this introduce a breaking change?

No

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

@codecov
Copy link

codecov bot commented Nov 11, 2022

Codecov Report

Base: 94.13% // Head: 94.80% // Increases project coverage by +0.66% 🎉

Coverage data is based on head (2fac372) compared to base (a99f949).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1238      +/-   ##
==========================================
+ Coverage   94.13%   94.80%   +0.66%     
==========================================
  Files          17       69      +52     
  Lines         597     3235    +2638     
  Branches       67      378     +311     
==========================================
+ Hits          562     3067    +2505     
- Misses         22      104      +82     
- Partials       13       64      +51     
Impacted Files Coverage Δ
python-sdk/src/astro/databases/aws/redshift.py 93.93% <100.00%> (ø)
python-sdk/src/astro/databases/base.py 96.09% <100.00%> (ø)
python-sdk/src/astro/databases/google/bigquery.py 94.56% <100.00%> (ø)
python-sdk/src/astro/databases/postgres.py 96.55% <100.00%> (ø)
python-sdk/src/astro/databases/snowflake.py 95.69% <100.00%> (ø)
python-sdk/src/astro/exceptions.py 100.00% <0.00%> (ø)
python-sdk/src/astro/sql/operators/drop.py 100.00% <0.00%> (ø)
python-sdk/src/astro/table.py 100.00% <0.00%> (ø)
... and 47 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add this check for postgres, redshift and bigquery too? Since we're overriding the load_pandas_dataframe_to_table method in those implementations too?

python-sdk/src/astro/databases/snowflake.py Outdated Show resolved Hide resolved
python-sdk/src/astro/databases/sqlite.py Outdated Show resolved Hide resolved
@pankajkoti
Copy link
Contributor

pankajkoti commented Nov 16, 2022

In my opinion, we should not be creating tables as part of load_pandas_dataframe_to_table if an empty dataframe is passed, as to me, it sounds like a side effect.
If the user really wants to create a table by passing an empty dataframe, we could add a separate method for that. But load_pandas_dataframe_to_table would mean load a dataframe and if that is empty, in my opinion, we should alert instead of silently just creating the table.

Copy link
Contributor

@sunank200 sunank200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that we should have a separate method which should check if dataframe is empty in the base class. That method can be overridden for Postgres and Bigquery.

python-sdk/src/astro/databases/snowflake.py Outdated Show resolved Hide resolved
@sunank200
Copy link
Contributor

In my opinion, we should not be creating tables as part of load_pandas_dataframe_to_table if an empty dataframe is passed, as to me, it sounds like a side effect. If the user really wants to create a table by passing an empty dataframe, we could add a separate method for that. But load_pandas_dataframe_to_table would mean load a dataframe and if that is empty, in my opinion, we should alert instead of silently just creating the table.

+1 on this. I feel we should not do multiple things as part of same method.

Copy link
Contributor

@sunank200 sunank200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't _assert_not_empty_df(df) be overridden for PostGres and Bigquery like you had mentioned?

python-sdk/src/astro/databases/base.py Show resolved Hide resolved
@pankajastro pankajastro merged commit 0690ac6 into main Nov 16, 2022
@pankajastro pankajastro deleted the handle_empty_dataframe branch November 16, 2022 12:20
kaxil pushed a commit that referenced this pull request Nov 16, 2022
# Description
closes: #810
## What is the current behavior?
In case of an empty dataframe the data frame operator throws an SQL
syntax error.

## What is the new behavior?
If the database does not support the creation of a table without a
the column then raises an error

## Does this introduce a breaking change?
No

### Checklist
- [ ] Created tests which fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary

(cherry picked from commit 0690ac6)
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

Successfully merging this pull request may close these issues.

aql.dataframe does not tolerate empty datafames
5 participants