def test_pandas_writes_header_by_default(): with tmpfile('.csv') as fn: ds = datashape.dshape('var * {name: string, amount: int}') data = [('Alice', 1), ('Bob', 2)] csv = CSV(fn) append(csv, data, dshape=ds) with open(fn) as f: assert 'name' in f.read()
def test_pandas_write_gzip(): with tmpfile('.csv.gz') as fn: ds = datashape.dshape('var * {name: string, amount: int}') data = [('Alice', 1), ('Bob', 2)] csv = CSV(fn, has_header=True) append(csv, data, dshape=ds) f = gzip.open(fn) s = f.read() assert 'name' in s assert 'Alice,1' in s f.close()
def test_csv_append(): with tmpfile('.csv') as fn: csv = CSV(fn, has_header=False) data = [('Alice', 100), ('Bob', 200)] append(csv, data) assert list(convert(Iterator, csv)) == data with open(fn) as f: s = f.read() assert 'Alice' in s assert '100' in s
def test_pandas_write(): with tmpfile('.csv') as fn: ds = datashape.dshape('var * {name: string, amount: int}') data = [('Alice', 1), ('Bob', 2)] csv = CSV(fn, has_header=True) append(csv, data, dshape=ds) with open(fn) as f: assert 'name' in f.read() # Doesn't write header twice append(csv, data, dshape=ds) with open(fn) as f: s = f.read() assert s.count('name') == 1