diff --git a/HISTORY.rst b/HISTORY.rst index 5a3d1c572f..fd84f34080 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -42,12 +42,13 @@ Unreleased Changes * Fixed a bug in HRA where the model would error when all exposure and consequence criteria were skipped for a single habitat. The model now correctly handles this case. https://github.com/natcap/invest/issues/1250 + * Tables in the .xls format are no longer supported. This format was + deprecated by ``pandas``. (`#1271 `_) * Scenic Quality * The Scenic Quality model will now raise an error when it encounters a geometry that is not a simple Point. This is in line with the user's guide chapter. https://github.com/natcap/invest/issues/1245 - 3.13.0 (2023-03-17) ------------------- * General diff --git a/src/natcap/invest/hra.py b/src/natcap/invest/hra.py index dee30fddfe..63ea8ccfb5 100644 --- a/src/natcap/invest/hra.py +++ b/src/natcap/invest/hra.py @@ -1834,10 +1834,10 @@ def _translate_op(*input_arrays): def _open_table_as_dataframe(table_path, **kwargs): extension = os.path.splitext(table_path)[1].lower() - # Technically, pandas.read_excel can handle xls, xlsx, xlsm, xlsb, odf, ods - # and odt file extensions, but I have not tested anything other than XLS - # and XLSX, so leaving this as-is from the prior HRA implementation. - if extension in {'.xls', '.xlsx'}: + # Technically, pandas.read_excel can handle xlsx, xlsm, xlsb, odf, ods + # and odt file extensions, but I have not tested anything other than + # XLSX, so leaving this as-is from the prior HRA implementation. + if extension == '.xlsx': excel_df = pandas.read_excel(table_path, **kwargs) excel_df.columns = excel_df.columns.str.lower() excel_df['path'] = excel_df['path'].apply( @@ -1906,7 +1906,7 @@ def _parse_criteria_table(criteria_table_path, target_composite_csv_path): included in this table. Args: - criteria_table_path (string): The path to a CSV, XLS or XLSX file on + criteria_table_path (string): The path to a CSV or XLSX file on disk. target_composite_csv_path (string): The path to where a new CSV should be written containing similar information but in a more easily @@ -1921,7 +1921,7 @@ def _parse_criteria_table(criteria_table_path, target_composite_csv_path): # This function requires that the table is read as a numpy array, so it's # easiest to read the table directly. extension = os.path.splitext(criteria_table_path)[1].lower() - if extension in {'.xls', '.xlsx'}: + if extension == '.xlsx': df = pandas.read_excel(criteria_table_path, header=None) else: df = pandas.read_csv(criteria_table_path, header=None, sep=None, @@ -2476,7 +2476,7 @@ def _override_datastack_archive_criteria_table_path( """ args_key = 'criteria_table_path' extension = os.path.splitext(criteria_table_path)[1].lower() - if extension in {'.xls', '.xlsx'}: + if extension == '.xlsx': df = pandas.read_excel(criteria_table_path, header=None) else: df = pandas.read_csv(criteria_table_path, header=None, sep=None, diff --git a/tests/test_hra.py b/tests/test_hra.py index d7f096d2e4..07b6b15c6c 100644 --- a/tests/test_hra.py +++ b/tests/test_hra.py @@ -758,7 +758,6 @@ def test_table_format_loading(self): expected_df['path'] = [os.path.join(self.workspace_dir, 'foo.tif')] for filename, func in [('target.csv', source_df.to_csv), - ('target.xls', source_df.to_excel), ('target.xlsx', source_df.to_excel)]: full_filepath = os.path.join(self.workspace_dir, filename) func(full_filepath, index=False)