ArrowNotImplementedError: halffloat error on applying pandas.to_feather on a dataframe

Viewed 3474

I have a dataframe with columns of different datatypes including dates. No after doing some modifications, i want to save it a feather file so as to access it later. But i am getting the error on the following step

historical_transactions.to_feather('tmp/historical-raw')

ArrowNotImplementedError: halffloat
3 Answers

I guess, in your dataframe, there is columns of dtype as float16 which is not supported in feather format. you can convert those columns to float32 and try.

You could try this:

    historical_transactions.astype('float32').to_feather('tmp/historical-raw')

Note that above line could fail if you also have fields that are not convertable into float32. In order to ignore those columns and leave them as they are, try:

    historical_transactions.astype('float32', errors='ignore').to_feather('tmp/historical-raw')

Feather format depends on Pyarrow which in turn depends on the Apache Parquet format. Regarding float formats, it only supports float (32) and double (64). Not sure how big of a deal this is for you but there is also an open request to automatically "Coerce Arrow half-precision float to float32" in GitHub.

See here and here for details.

Improving on Kocas' answer, converting exclusively the half-float columns

half_floats = historical_transactions.select_dtypes(include="float16")
historical_transactions[half_floats.columns] = half_floats.astype("float32")
historical_transactions.to_feather('tmp/historical-raw')
Related