nickmckay / LiPD-utilities

Input/output and manipulation utilities for LiPD files in Matlab, R and Python
http://nickmckay.github.io/LiPD-utilities/
GNU General Public License v2.0
29 stars 9 forks source link

Python: FileNotFoundError in readExcel when changing dir back to cwd #82

Open ghost opened 3 years ago

ghost commented 3 years ago

Possible duplicate of #68 if that's using the same utility function?

I'm attempting to read the example Stott et al. 2004 Excel file and convert to LiPD. My python file (excel2lipd.py) is in a code directory, and the excel file is in a data directory on the same level:

project/
  ├─ data/
  │    └─ MD982176.Stott.2004.xls
  └─ code/
       └─ excel2lipd.py

with the code

import lipd

lipd.readExcel("../data/MD982176.Stott.2004.xls")
D = lipd.excel()

I get the output:

reading: MD982176.Stott.2004.xls
Found 1 Excel files
processing: MD982176.Stott.2004.xls
- Error: Variables are not entered correctly in sheet: paleo1measurement1
        Unmatched variables: {'d18ob.rub', 'd18og.rub'}
Failed : MD982176.Stott.2004 [0]: No DOI key in publication
Traceback (most recent call last):
  File "/project/code/excel2lipd.py", line 6, in <module>
    D = lipd.excel()
  File "/home/tom/.local/share/virtualenvs/code-ueoh45zC/lib/python3.8/site-packages/lipd/__init__.py", line 171, in excel
    os.chdir(cwd)
FileNotFoundError: [Errno 2] No such file or directory: '../data'

If I run the same script but with the XLS in the same directory as the python file, I get a similar error:

reading: MD982176.Stott.2004.xls
Traceback (most recent call last):
  File "/project/code/excel2lipd.py", line 5, in <module>
    lipd.readExcel("MD982176.Stott.2004.xls")
  File "/home/tom/.local/share/virtualenvs/code-ueoh45zC/lib/python3.8/site-packages/lipd/__init__.py", line 88, in readExcel
    os.chdir(cwd)
FileNotFoundError: [Errno 2] No such file or directory: ''

...and no LiPD file created in either case. It also doesn't work with my own Excel template XLS.