Search code examples
pythonsqlalchemypyexcel

How to suppress PyExcel Empty Row Warning during file read to SQLAlclemy model


I am saving the contents of an excel file to a SQLAlchemy DB table using pyexcel as following: pyexcel.save_as(file_name='my_excel_file.xlsx',
name_columns_by_row=0,
dest_session=db.session,
dest_table=models.MyModel)

This is working well and saving the data but it's leaving several log messages that One empty row is found in the terminal. How do I suppress these messages to avoid polluting the logs? I know about the empty rows and they have no impact to the data loading


Solution

  • So turns out pyexcel does a bit more on abstractions, the heavy lifting is done by pyexcel-io which does the basic input and output. With this understanding, in the pyexcel docs there is a parameter skip_empty_rows=True for when you reading from a source file which if you pass to the pyexcel.save_as function and this silences the logged messages, so it was exactly what I needed in this use-case. See PyExcel Docs Ref for pyexcel.save_as