-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
.astype(SparseDtype(float)) on empty dataframe leads to "ValueError: No objects to concatenate" #33113
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
Comments
Thanks @tgy for the report. The same exception is raised for Int64Dtype, StringDtype and BooleanDtype and maybe more. |
@simonjayhawkins yep, i used |
My motivation is to make one line of code robust to "blank" inputs. And I encountered the same kind of error for slightly different input...
This is all good (aside from "missing" bool being True)...
this is also fine...
... but... for a list of empty dict(), my actual_dtypes will also be an empty dict()...
So perhaps a short circuit for empty dataframes? (instead of raising error?) |
@KardoPaska My small change on #33118 seems to fix your issue as well:
Waiting for @jreback to approve the change on the PR |
Shouldn't the code be |
Code Sample, a copy-pastable example if possible
Problem description
Converting an empty dataframe to a sparse representation leads to a
ValueError
.Expected Output
I expected this to work even though the dataframe is empty.
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: