Commit 751e3842 authored by Asitha Senanayake's avatar Asitha Senanayake
Browse files

fix(#126): stop None/NA strings from being converted to NaN when parsing .xlsx

Conversion of None/NA values to NaN results in those values disappearing
when the file is written back a .ags file.
parent 57fabc1f
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -431,7 +431,8 @@ def excel_to_AGS4(input_file, output_file, format_numeric_columns=True, dictiona
    from pandas import read_excel

    # Read data from Excel file in to a dictionary of dataframes
    tables = read_excel(input_file, sheet_name=None, engine='openpyxl')
    tables = read_excel(input_file, sheet_name=None, engine='openpyxl',
                        keep_default_na=False, na_values='')

    # Not all worksheets in the spreadsheet may contain valid AGS4 tables, therefore
    # initiate variable to keep track of worksheets to export
−131 B (12.8 KiB)

File changed.

No diff preview for this file type.

+5 −0
Original line number Diff line number Diff line
@@ -216,6 +216,11 @@ def test_excel_to_AGS4():
    assert 'NEWCOLUMN' not in tables['LOCA'].columns
    assert 'stray_data' not in tables['LOCA'].values

    # Check whether None values in Excel are parsed as is rather than
    # being converted to NaN
    assert tables['PROJ'].loc[2, 'PROJ_LOC'] == 'None'
    assert tables['PROJ'].loc[2, 'PROJ_CLNT'] == 'NA'

    # Call function with dictionary file
    AGS4.excel_to_AGS4('tests/test.xlsx', 'tests/test.out', dictionary='tests/DICT.ags')