Skip to content

Commit

Permalink
Add note about csvcut truncating long rows, #992
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Nov 7, 2018
1 parent 0f53b29 commit ddba23d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/scripts/csvcut.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ See also: :doc:`../common_arguments`.

csvcut does not implement row filtering, for this you should pipe data to :doc:`csvgrep`.

.. note::

If a data row is longer than the header row, its additional columns are truncated. Use :doc:`csvclean` first to fix such rows.

Examples
========

Expand Down Expand Up @@ -71,7 +75,6 @@ Print only the names of all columns, by removing the indices with the :code:`cut
Post-Vietnam Era Veteran's Educational Assistance Program
TOTAL


Extract the first and third columns::

csvcut -c 1,3 examples/realdata/FY09_EDU_Recipients_by_State.csv
Expand All @@ -92,4 +95,3 @@ Extract a column that may not exist in all files::
Display a column's unique values::

csvcut -c 1 examples/realdata/FY09_EDU_Recipients_by_State.csv | sed 1d | sort | uniq

16 changes: 15 additions & 1 deletion tests/test_utilities/test_csvcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,21 @@ def test_no_header_row(self):

def test_ragged(self):
# Test that csvcut doesn't error when a row is short.
self.get_output(['-c', 'column_c', 'examples/bad.csv'])
self.assertRows(['-c', 'column_c', 'examples/bad.csv'], [
['column_c'],
[],
[],
['17'],
])

def test_truncate(self):
# Test that csvcut truncates long rows.
self.assertRows(['-C', 'column_a,column_b', 'examples/bad.csv'], [
['column_c'],
[],
[],
['17'],
])

def test_names_with_skip_lines(self):
self.assertLines(['--names', '--skip-lines', '3', 'examples/test_skip_lines.csv'], [
Expand Down

0 comments on commit ddba23d

Please sign in to comment.