Closed VDFaller closed 1 year ago
I can fix it by adding
if df.empty:
df = pd.DataFrame(columns=dtypes.keys())
right before it.
Thanks for the note. If you’d like to create a pull request with a test it would be very welcome
Already making the MR. I don't know how to use tableau so I don't know how to make a hyper , but I'll see if someone can help me over here.
I think you can still use pantab to write an empty dataframe? Or is that not working either?
Good point. I'll try that.
Seems that frame_to_hyper
also doesn't work.
import pantab
import pathlib
from tableauhyperapi import TableName
datapath = pathlib.Path(__file__).parent / "data"
db_path = datapath / "zero_row.hyper"
df_expected = pd.DataFrame(columns = ['A'])
pantab.frame_to_hyper(df_expected, db_path, table = TableName('not_the_public_schema', 'zero_row'))
This seems to be in libpantab, and I'm not comfortable enough to touch the C.
That is unfortunate. Well if you are feeling ambitious here's a guide I wrote in pandas for how to debug their C extensions. The same rules should apply here in pantab
https://pandas.pydata.org/docs/development/debugging_extensions.html
Alternately we could also just return early if the data frame is empty during write, not even invoking the tableau inserter.
Definitely an untested case here with reading/writing empty frames. Would make for a good scenario to put into test_roundtrip.py
Don't know if I have that kind of ambition at the moment. But would it be helpful if I made a test_roundtrip.py
test for it? maybe with a @pytest.mark.skip(reason="currently failing #163")
?
I think the test there should work for reading/writing. I know the OP was just about reading but looks like neither work with an empty frame. Would make sense to fix togethee
Describe the bug I'm simply trying to pull all the frames from a hyper file (which I unfortunately can't give you). But I think the problem is that one of the tables doesn't have any rows. Which then errors out here with
df in the line above is an empty dataframe.
This is a problem because it's screwing up my other reads.
Expected behavior It gives me a blank dataframe with the proper columns but no data.
Could skip it too, but that seems worse.
Desktop (please complete the following information):