PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
300 stars 47 forks source link

Pathlib incompatibility and case sensitivity #11

Closed samukweku closed 4 years ago

samukweku commented 4 years ago

Not sure if I used the right headers for this issue; these are things I noticed when trying out ur application. I like the idea of minimal dependencies and would love to use the program especially when heavy duty transformations that require Pandas are not required.

Anyways, here goes my observations:

Running pylightxl-1.41

  1. You cant read a file directly using Pathlib, u need to convert it back to a string
from pathlib import Path
import pylightxl as xl

folder = Path('excelfiles')

{f.stem:xl.readxl(f) for f in folder.rglob('*.xls*')}
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
----> 1 {f.stem:xl.readxl(f) for f in folder.rglob('*.xls*')}

 in (.0)
----> 1 {f.stem:xl.readxl(f) for f in folder.rglob('*.xls*')}

~/miniforge3/envs/pydata/lib/python3.8/site-packages/pylightxl/readxl.py in readxl(fn, sheetnames)
     21 
     22     # test that file entered was a valid excel file
---> 23     check_excelfile(fn)
     24 
     25     # zip up the excel file to expose the xml files

~/miniforge3/envs/pydata/lib/python3.8/site-packages/pylightxl/readxl.py in check_excelfile(fn)
     76 
     77     if type(fn) is not str:
---> 78         raise ValueError('Error - Incorrect file entry ({}).'.format(fn))
     79 
     80     if not isfile(fn):

ValueError: Error - Incorrect file entry (excelfiles/Seattle.xlsx).

However, when I add the str wrapper to it, everything works fine.

{f.stem:xl.readxl(str(f)) for f in folder.rglob('*.xls*')}

{'Seattle': pylightxl.Database,
 'Portland': pylightxl.Database,
 'Oakland': pylightxl.Database}
  1. pylightxl is case sensitive when it comes to the suffixes. It wont accept uppercase XLSX:

{f.stem:xl.readxl(str(f)) for f in folder.rglob('*.XLSX*')}

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
----> 1 {f.stem:xl.readxl(f) for f in folder.rglob('*.XLSX*')}

 in (.0)
----> 1 {f.stem:xl.readxl(f) for f in folder.rglob('*.XLSX*')}

~/miniforge3/envs/pydata/lib/python3.8/site-packages/pylightxl/readxl.py in readxl(fn, sheetnames)
     21 
     22     # test that file entered was a valid excel file
---> 23     check_excelfile(fn)
     24 
     25     # zip up the excel file to expose the xml files

~/miniforge3/envs/pydata/lib/python3.8/site-packages/pylightxl/readxl.py in check_excelfile(fn)
     76 
     77     if type(fn) is not str:
---> 78         raise ValueError('Error - Incorrect file entry ({}).'.format(fn))
     79 
     80     if not isfile(fn):

ValueError: Error - Incorrect file entry (excelfiles/Tacoma.XLSX).
PydPiper commented 4 years ago

Hi @samukweku, really appreciate the feedback. I am taking a look at the fixes now. There has been a few pull requests/bug-fixes since v1.41 so we are getting ready for v1.42 with these changes rolled in

PydPiper commented 4 years ago

The latest commit contains the support for pathlib. Let me know if you are find anything else. The new version that will contain the fix will most likely not come out for a week or so. Still trying to add a few features before pushing a new version to pip, but for now please git clone the latest copy and see if that works out for you