USEPA / LCIAformatter

MIT License
24 stars 9 forks source link

xlrd error getting methods #57

Closed mfastudillo closed 3 years ago

mfastudillo commented 3 years ago

Hi!

I was trying the library and running recipe2016 = lciafmt.get_method(lciafmt.Method.RECIPE_2016) I got the following error

imagen

it seems to be caused by xlrd ending support for non-xls files. I installed pandas before lciafmt, and I ended up with version 2.0.1 fo xlrd... an alternative may be to switch to openpyx for xlsx files...

openjournals/joss-reviews#3392

bl-young commented 3 years ago

@mfastudillo yes it appears that the latest release of xlrd will not work. I will likely switch to openpyxl. In the meantime, you may want to downgrade to 1.2 to continue testing

bl-young commented 3 years ago

requirements specified <2.0 for temporary resolution https://github.com/USEPA/LCIAformatter/commit/6410043d25b87cf6256743c25d90a5b27dafa397

tngTUDOR commented 3 years ago

Same here, with the first "Use examples from the wiki":

If you modify the dependency in the setup.py for xlrd to :

diff --git a/setup.py b/setup.py
index 9ab4b5d..320f3d2 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ setup(
                       "esupy @ git+git://github.com/USEPA/esupy@v0.1.1#egg=esupy",
                       "olca-ipc>=0.0.8",
                       "pandas>=0.22",
-                      "xlrd>=1.2.0",
+                      "xlrd<1.2.0",
                       "pyyaml>=5.3",
                       "pyodbc>=4.0.30",
                       ],

installing in a "clean" environment would be flawless

(for completenes here are the erros I get)

import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
---------------------------------------------------------------------------
XLRDError                                 Traceback (most recent call last)
/tmp/ipykernel_27973/1751509404.py in <module>
      1 import lciafmt
----> 2 traci = lciafmt.get_method(lciafmt.Method.TRACI)

~/miniconda3/envs/lciaformatter/lib/python3.9/site-packages/lciafmt/__init__.py in get_method(method_id, add_factors_for_missing_contexts, endpoint, summary, file, subset, url)
     75     method_id = util.check_as_class(method_id)
     76     if method_id == Method.TRACI:
---> 77         return traci.get(add_factors_for_missing_contexts, file=file, url=None)
     78     if method_id == Method.RECIPE_2016:
     79         return recipe.get(add_factors_for_missing_contexts, endpoint, summary, file=file, url=url)

~/miniconda3/envs/lciaformatter/lib/python3.9/site-packages/lciafmt/traci.py in get(add_factors_for_missing_contexts, file, url)
     32                    "traci_2_1_2014_dec_10_0.xlsx")
     33         f = cache.get_or_download(fname, url)
---> 34     df = _read(f)
     35     if add_factors_for_missing_contexts:
     36         log.info("adding average factors for primary contexts")

~/miniconda3/envs/lciaformatter/lib/python3.9/site-packages/lciafmt/traci.py in _read(xls_file)
     68 
     69     log.info("read Traci 2.1 from file %s", xls_file)
---> 70     wb = xlrd.open_workbook(xls_file)
     71     sheet = wb.sheet_by_name("Substances")
     72 

~/miniconda3/envs/lciaformatter/lib/python3.9/site-packages/xlrd/__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)
    168     # files that xlrd can parse don't start with the expected signature.
    169     if file_format and file_format != 'xls':
--> 170         raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
    171 
    172     bk = open_workbook_xls(

XLRDError: Excel xlsx file; not supported
mfastudillo commented 3 years ago

Hi

I ended up cloning the repo and using the setup file of the joss_review branch to install the library. When I try to get the TRACI method I have a different error.

image

the xlrd version installed is 1.2.0

WesIngwersen commented 3 years ago

It appears that we should try the alternative library proposed openpyxl because of these versioning issues with xlrd @bl-young

bl-young commented 3 years ago

I will work on resolving this issue to shift to openpyxl and will let you know when it has been fixed @mfastudillo @tngTUDOR. It seems that starting with python 3.9 xlrd will not work even with version 1.2