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

Loosen xlrd requirement #572

Merged
merged 6 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/workflows/pytest-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install specific out-dated version of dependencies
# Update the package requirements when changing minimum dependency versions
# Please also add a section "Dependency changes" to the release notes
run: pip install pandas==1.1.1 numpy==1.19.0 matplotlib==3.2.0 iam-units==2020.4.21
run: pip install pandas==1.1.1 numpy==1.19.0 matplotlib==3.2.0 iam-units==2020.4.21 xlrd==2.0

- name: Install other dependencies and package
run: pip install -e .[tests,deploy,optional-plotting,optional-io-formats,tutorials]
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Individual updates

PR [#572](https://github.com/IAMconsortium/pyam/pull/572) unpinned the requirements for xlrd and added openpyxl as a requirement to ensure ongoing support of both `.xlsx` and `.xls` files out of the box
znicholls marked this conversation as resolved.
Show resolved Hide resolved

# Release v1.1.0

## Highlights
Expand Down
2 changes: 1 addition & 1 deletion pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _init(self, data, meta=None, index=DEFAULT_META_INDEX, **kwargs):

# if initializing from xlsx, try to load `meta` table from file
if meta_sheet and isinstance(data, Path) and data.suffix == ".xlsx":
excel_file = pd.ExcelFile(data)
excel_file = pd.ExcelFile(data, engine="openpyxl")
if meta_sheet in excel_file.sheet_names:
self.load_meta(excel_file, sheet_name=meta_sheet, ignore_conflict=True)

Expand Down
10 changes: 8 additions & 2 deletions pyam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ def read_pandas(path, sheet_name="data*", *args, **kwargs):
if isinstance(path, Path) and path.suffix == ".csv":
return pd.read_csv(path, *args, **kwargs)
else:
xl = pd.ExcelFile(path)
if isinstance(path, pd.ExcelFile):
xl = path
else:
xl = pd.ExcelFile(
path, engine="xlrd" if path.suffix == ".xls" else "openpyxl"
)

sheet_names = pd.Series(xl.sheet_names)

# reading multiple sheets
Expand All @@ -153,7 +159,7 @@ def read_pandas(path, sheet_name="data*", *args, **kwargs):

# read single sheet (if only one exists in file) ignoring sheet name
else:
df = pd.read_excel(path, *args, **kwargs)
df = pd.read_excel(xl, *args, **kwargs)

# remove unnamed and empty columns, and rows were all values are nan
def is_empty(name, s):
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@

# NOTE TO DEVS
# If you change a minimum version below, please explicitly implement the change
# in our minimum-reqs test in the file ./.github/workflows/pytest-depedency.yml
# in our minimum-reqs test in the file ./.github/workflows/pytest-dependency.yml
# Please also add a section "Dependency changes" to the release notes
REQUIREMENTS = [
"argparse",
"iam-units>=2020.4.21",
"numpy>=1.19.0",
"requests",
"openpyxl",
znicholls marked this conversation as resolved.
Show resolved Hide resolved
"pandas>=1.1.1",
"pint",
"PyYAML",
"matplotlib>=3.2.0",
"seaborn",
"six",
"xlrd<2.0",
"xlrd>=2.0",
]

EXTRA_REQUIREMENTS = {
Expand All @@ -44,7 +45,6 @@
"sphinxcontrib-bibtex<2.0",
"sphinxcontrib-programoutput",
"numpydoc",
"openpyxl",
"kaleido",
] # docs requires 'tutorials'
# GitHub Actions requires pandoc explicitly to build the docs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_init_df_with_na_unit(test_pd_df, tmpdir):

file = tmpdir / "na_unit.xlsx"
df.to_excel(file)
df_excel = pd.read_excel(file)
df_excel = pd.read_excel(file, engine="openpyxl")
assert np.isnan(df_excel.loc[1, "Unit"])
IamDataFrame(file) # reading from file as IamDataFrame works

Expand Down