Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove XLS format from HRA #1272

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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