nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
751 stars 530 forks source link

CSVReader does not handle quoted fields or tsv files #3635

Closed zachlindsey closed 8 months ago

zachlindsey commented 8 months ago

Summary

I want to add functionality to the CSVReader so it can handle tsv files. While checking that out, I noticed that we're just splitting on ,, which is not ideal.

Actual behavior

Parsing CSV files with fields that contain quoted text with ',' characters does not work correctly. TSV files are not supported.

Expected behavior

Quoted fields should be correctly parsed if they contain the delimiter.

How to replicate the behavior

Run the script below.

Script/Workflow details

from nipype.interfaces import utility

reader = utility.CSVReader()

lines = ["foo,\"hello,world\",300.1\n"]

with open("testcsv.csv", "w") as fid:
    fid.writelines(lines)
    fid.flush()

reader.inputs.in_file = "testcsv.csv"
out = reader.run()

assert out.outputs.column_1 == ["hello, world"]

Platform details:

{'commit_hash': 'c46a957bd',
 'commit_source': 'repository',
 'networkx_version': '3.2.1',
 'nibabel_version': '5.2.1',
 'nipype_version': '1.8.7.dev0',
 'numpy_version': '1.26.4',
 'pkg_path': '/home/USER/Desktop/nipype/nipype',
 'scipy_version': '1.12.0',
 'sys_executable': '/home/USER/Desktop/nipype/.venv/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.9.18 (main, Feb  1 2024, 11:48:51) \n[GCC 11.4.0]',
 'traits_version': '6.3.2'}

Execution environment

zachlindsey commented 8 months ago

3637