codeinthehole / csvfilter

Command-line tool for manipulating CSV data
http://codeinthehole.com/writing/csvfilter-a-python-command-line-tool-for-manipulating-csv-data/
MIT License
75 stars 15 forks source link

fields don't work #13

Open lk-jeffpeck opened 6 years ago

lk-jeffpeck commented 6 years ago
$ csvfilter -f 1,2,3 file.csv

Expected: Output columns 1, 2, and 3 from file.csv for all rows

Actual: Only outputs columns 1, 2, and 3 from the first row.


It looks like the reason for this is:

fields = map(int, options.fields.split(',')) if options.fields else None

... which is being consumed after the first row:

output = [row[i] for i in self.fields if len(row) > i]

after which self.fields becomes an empty array: []

A solution would be:

fields = list(map(int, options.fields.split(','))) if options.fields else None

This PR should resolve: https://github.com/codeinthehole/csvfilter/pull/12

joaomcarlos commented 5 years ago

Why hasnt this been merged in yet? The tool is broken.

In the meantime, if anyone is trying to get stuff done: pip install --upgrade git+https://github.com/lk-jeffpeck/csvfilter.git@ec433f14330fbbf5d41f56febfeedac22868a949

That will install Jeffs pull request on your machine and let you get on with your work.

Thanks Jeff btw

keenhl commented 5 years ago

@silentwarrior @lk-jeffpeck Thanks for the fix and for the link to the fix.

pinturic commented 1 year ago

+1 for me with @joaomcarlos fix it works perfectly

Eddie901 commented 1 year ago

Thanks @lk-jeffpeck @joaomcarlos fix worked for me too 🙌

@codeinthehole Any chance it could be merged?