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

Ignore empty lines #115

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions datalad_tabby/io/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ def _load_many(
for row_id, row in enumerate(reader):
# row is a list of field, with only as many items
# as this particular row has columns
if not len(row) \
or row[0].startswith('#') \
or all(v is None for v in row):
if (
not len(row)
or row[0].startswith("#")
or all(v is None for v in row)
or all(v == "" for v in row)
):
# skip empty rows, rows with no key, or rows with
# a comment key
continue
Expand Down
11 changes: 10 additions & 1 deletion datalad_tabby/io/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ def _sheet2tsv(ws: Worksheet, dest: Path):
tsvfile,
delimiter='\t',
)
writer.writerows(ws.iter_rows(values_only=True))

# find the last nonempty row
max_idx = 1
for i, row in enumerate(ws.iter_rows(values_only=True)):
if any(v is not None for v in row):
max_idx = i + 1 # max row is a 1-based index

# write tsv, truncating empty rows at the end
writer.writerows(ws.iter_rows(values_only=True, max_row=max_idx))

4 changes: 0 additions & 4 deletions datalad_tabby/tests/data/demorecord/tabbydemo_files.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ path[POSIX] size[bytes] checksum[md5] url
raw/adelie.csv 23755 e7e2be6b203a221949f05e02fcefd853 https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.3&entityid=002f3893385f710df69eeebe893144ff
raw/gentoo.csv 11263 1549566fb97afa879dc9446edcf2015f https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.3&entityid=e03b43c924f226486f2f0ab6709d2381
raw/chinstrap.csv 18872 e4b0710c69297031d63866ce8b888f25 https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.2&entityid=fe853aa8f7a59aa84cdd3197619ef462




Loading