df.to_sql error : 'h' format requires -32768 <= number <= 32767

Viewed 24

I am trying to ingest a dataframe to postgres db using python script in AWS Glue. It processes some dataframes, but for some dataframes, while doing df.to_sql it gives

'h' format requires -32768 <= number <= 32767

If someone has experience with such kind of error, inputs are welcome. Thanks.

enter image description here

1 Answers

'h' is stored with a smallint on 2 bytes (-32768 to +32767).

You must ensure that the column holding your hours are within those bounds.

If you originally have integers, you can use clip(-32768, 32767) to enforce those limits, or drop the invalid data.

Related