Skip to content

Commit

Permalink
Merge pull request #1272 from emlys/bugfix/1271
Browse files Browse the repository at this point in the history
Remove XLS format from HRA
  • Loading branch information
dcdenu4 authored Apr 5, 2023
2 parents d4f846b + ed18bf9 commit b1b6715
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/natcap/invest/issues/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
Expand Down
14 changes: 7 additions & 7 deletions src/natcap/invest/hra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_hra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b1b6715

Please sign in to comment.