Python csv.QUOTE_NONE Examples
The following are 30
code examples of csv.QUOTE_NONE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
csv
, or try the search function
.
Example #1
Source File: test_csv.py From Fluid-Designer with GNU General Public License v3.0 | 7 votes |
def test_write_arg_valid(self): self._write_error_test(csv.Error, None) self._write_test((), '') self._write_test([None], '""') self._write_error_test(csv.Error, [None], quoting = csv.QUOTE_NONE) # Check that exceptions are passed up the chain class BadList: def __len__(self): return 10; def __getitem__(self, i): if i > 2: raise OSError self._write_error_test(OSError, BadList()) class BadItem: def __str__(self): raise OSError self._write_error_test(OSError, [BadItem()])
Example #2
Source File: csv_file.py From recon-ng-marketplace with GNU General Public License v3.0 | 7 votes |
def __parse_file(self): filename = self.options['filename'] if not filename: raise IOError sep = self.options['column_separator'] quote = self.options['quote_character'] values = [] with open(filename, newline='') as infile: # if sep is not a one character string, csv.reader will raise a TypeError if not quote: csvreader = csv.reader(infile, delimiter=str(sep), quoting=csv.QUOTE_NONE) else: csvreader = csv.reader(infile, delimiter=str(sep), quotechar=str(quote)) # get each line from the file and separate it into columns based on sep for row in csvreader: # append all lines as-is case-wise values.append([value.strip() for value in row]) # ensure the number of columns in each row is the same as the previous row if len(values) > 1: assert len(values[-1]) == len(values[-2]) return values
Example #3
Source File: celex.py From wordkit with GNU General Public License v3.0 | 7 votes |
def _celex(path, fields, lemmas, language): w_length, s_length = lengths[(language, lemmas)] _opener = partial(_celex_opener, word_length=w_length, struct_length=s_length) return reader(path, fields, PROJECT2FIELD[(language, lemmas)], language, delimiter="\\", quoting=csv.QUOTE_NONE, opener=_opener, preprocessors={"phonology": phon_func, "syllables": syll_func})
Example #4
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 7 votes |
def test_lineterminator(self): class mydialect(csv.Dialect): delimiter = ";" escapechar = '\\' doublequote = False skipinitialspace = True lineterminator = '\r\n' quoting = csv.QUOTE_NONE d = mydialect() self.assertEqual(d.lineterminator, '\r\n') mydialect.lineterminator = ":::" d = mydialect() self.assertEqual(d.lineterminator, ":::") mydialect.lineterminator = 4 with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), '"lineterminator" must be a string')
Example #5
Source File: test_csv.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', escapechar='\\') self._write_error_test(csv.Error, ['a',1,'p,"q"'], escapechar=None, doublequote=False) self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar='\\', doublequote = False) self._write_test(['"'], '""""', escapechar='\\', quoting = csv.QUOTE_MINIMAL) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_MINIMAL, doublequote = False) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_NONE) self._write_test(['a',1,'p,q'], 'a,1,p\\,q', escapechar='\\', quoting = csv.QUOTE_NONE)
Example #6
Source File: test_python_parser_only.py From recruit with Apache License 2.0 | 6 votes |
def test_multi_char_sep_quotes(python_parser_only, quoting): # see gh-13374 kwargs = dict(sep=",,") parser = python_parser_only data = 'a,,b\n1,,a\n2,,"2,,b"' msg = "ignored when a multi-char delimiter is used" def fail_read(): with pytest.raises(ParserError, match=msg): parser.read_csv(StringIO(data), quoting=quoting, **kwargs) if quoting == csv.QUOTE_NONE: # We expect no match, so there should be an assertion # error out of the inner context manager. with pytest.raises(AssertionError): fail_read() else: fail_read()
Example #7
Source File: ljspeech.py From audio with BSD 2-Clause "Simplified" License | 6 votes |
def __init__(self, root: str, url: str = URL, folder_in_archive: str = FOLDER_IN_ARCHIVE, download: bool = False) -> None: basename = os.path.basename(url) archive = os.path.join(root, basename) basename = basename.split(self._ext_archive)[0] folder_in_archive = os.path.join(basename, folder_in_archive) self._path = os.path.join(root, folder_in_archive) self._metadata_path = os.path.join(root, basename, 'metadata.csv') if download: if not os.path.isdir(self._path): if not os.path.isfile(archive): checksum = _CHECKSUMS.get(url, None) download_url(url, root, hash_value=checksum) extract_archive(archive) with open(self._metadata_path, "r") as metadata: walker = unicode_csv_reader(metadata, delimiter="|", quoting=csv.QUOTE_NONE) self._walker = list(walker)
Example #8
Source File: test_dialect.py From recruit with Apache License 2.0 | 6 votes |
def test_dialect(all_parsers): parser = all_parsers data = """\ label1,label2,label3 index1,"a,c,e index2,b,d,f """ dia = csv.excel() dia.quoting = csv.QUOTE_NONE df = parser.read_csv(StringIO(data), dialect=dia) data = """\ label1,label2,label3 index1,a,c,e index2,b,d,f """ exp = parser.read_csv(StringIO(data)) exp.replace("a", "\"a", inplace=True) tm.assert_frame_equal(df, exp)
Example #9
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_write_arg_valid(self): self._write_error_test(csv.Error, None) self._write_test((), '') self._write_test([None], '""') self._write_error_test(csv.Error, [None], quoting = csv.QUOTE_NONE) # Check that exceptions are passed up the chain class BadList: def __len__(self): return 10; def __getitem__(self, i): if i > 2: raise IOError self._write_error_test(IOError, BadList()) class BadItem: def __str__(self): raise IOError self._write_error_test(IOError, [BadItem()])
Example #10
Source File: filter_options.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
def export_to_csv(request, variants): #export to csv export = request.GET.get('export', '') if export != '': if export == 'csv': response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=export.csv' writer = csv.writer(response) elif export == 'txt': response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=export.txt' writer = csv.writer(response, delimiter='\t', quoting=csv.QUOTE_NONE) writer.writerow(['Individual', 'Index', 'Pos_index', 'Chr', 'Pos', 'Variant_id', 'Ref', 'Alt', 'Qual', 'Filter', 'Info', 'Format', 'Genotype_col', 'Genotype', 'Read_depth', 'Gene', 'Mutation_type', 'Vartype', 'Genomes1k_maf', 'Dbsnp_maf', 'Esp_maf', 'Dbsnp_build', 'Sift', 'Sift_pred', 'Polyphen2', 'Polyphen2_pred', 'Condel', 'Condel_pred', 'DANN', 'CADD', 'Is_at_omim', 'Is_at_hgmd', 'Hgmd_entries', 'Effect', 'Impact', 'Func_class', 'Codon_change', 'Aa_change', 'Aa_len', 'Gene_name', 'Biotype', 'Gene_coding', 'Transcript_id', 'Exon_rank', 'Genotype_number', 'Allele', 'Gene', 'Feature', 'Feature_type', 'Consequence', 'Cdna_position', 'Cds_position', 'Protein_position', 'Amino_acids', 'Codons', 'Existing_variation', 'Distance', 'Strand', 'Symbol', 'Symbol_source', 'Sift', 'Polyphen', 'Condel']) for variant in variants: # print 'variant', variant.index writer.writerow([variant.individual, variant.index, variant.pos_index, variant.chr, variant.pos, variant.variant_id, variant.ref, variant.alt, variant.qual, variant.filter, pickle.loads(variant.info), variant.format, variant.genotype_col, variant.genotype, variant.read_depth, variant.gene, variant.mutation_type, variant.vartype, variant.genomes1k_maf, variant.dbsnp_maf, variant.esp_maf, variant.dbsnp_build, variant.sift, variant.sift_pred, variant.polyphen2, variant.polyphen2_pred, variant.condel, variant.condel_pred, variant.dann, variant.cadd, variant.is_at_omim, variant.is_at_hgmd, variant.hgmd_entries]) return response
Example #11
Source File: filter_options.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
def export_to_csv(request, variants): #export to csv export = request.GET.get('export', '') if export != '': if export == 'csv': response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=export.csv' writer = csv.writer(response) elif export == 'txt': response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=export.txt' writer = csv.writer(response, delimiter='\t', quoting=csv.QUOTE_NONE) writer.writerow(['Individual', 'Index', 'Pos_index', 'Chr', 'Pos', 'Variant_id', 'Ref', 'Alt', 'Qual', 'Filter', 'Info', 'Format', 'Genotype_col', 'Genotype', 'Read_depth', 'Gene', 'Mutation_type', 'Vartype', 'Genomes1k_maf', 'Dbsnp_maf', 'Esp_maf', 'Dbsnp_build', 'Sift', 'Sift_pred', 'Polyphen2', 'Polyphen2_pred', 'Condel', 'Condel_pred', 'DANN', 'CADD', 'Is_at_omim', 'Is_at_hgmd', 'Hgmd_entries', 'Effect', 'Impact', 'Func_class', 'Codon_change', 'Aa_change', 'Aa_len', 'Gene_name', 'Biotype', 'Gene_coding', 'Transcript_id', 'Exon_rank', 'Genotype_number', 'Allele', 'Gene', 'Feature', 'Feature_type', 'Consequence', 'Cdna_position', 'Cds_position', 'Protein_position', 'Amino_acids', 'Codons', 'Existing_variation', 'Distance', 'Strand', 'Symbol', 'Symbol_source', 'Sift', 'Polyphen', 'Condel']) for variant in variants: # print 'variant', variant.index writer.writerow([variant.individual, variant.index, variant.pos_index, variant.chr, variant.pos, variant.variant_id, variant.ref, variant.alt, variant.qual, variant.filter, pickle.loads(variant.info), variant.format, variant.genotype_col, variant.genotype, variant.read_depth, variant.gene, variant.mutation_type, variant.vartype, variant.genomes1k_maf, variant.dbsnp_maf, variant.esp_maf, variant.dbsnp_build, variant.sift, variant.sift_pred, variant.polyphen2, variant.polyphen2_pred, variant.condel, variant.condel_pred, variant.dann, variant.cadd, variant.is_at_omim, variant.is_at_hgmd, variant.hgmd_entries]) return response
Example #12
Source File: filter_options.py From mendelmd with BSD 3-Clause "New" or "Revised" License | 6 votes |
def export_to_csv(request, variants): #export to csv export = request.GET.get('export', '') if export != '': if export == 'csv': response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=export.csv' writer = csv.writer(response) elif export == 'txt': response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=export.txt' writer = csv.writer(response, delimiter='\t', quoting=csv.QUOTE_NONE) writer.writerow(['Individual', 'Index', 'Pos_index', 'Chr', 'Pos', 'Variant_id', 'Ref', 'Alt', 'Qual', 'Filter', 'Info', 'Format', 'Genotype_col', 'Genotype', 'Read_depth', 'Gene', 'Mutation_type', 'Vartype', 'Genomes1k_maf', 'Dbsnp_maf', 'Esp_maf', 'Dbsnp_build', 'Sift', 'Sift_pred', 'Polyphen2', 'Polyphen2_pred', 'Condel', 'Condel_pred', 'DANN', 'CADD', 'Is_at_omim', 'Is_at_hgmd', 'Hgmd_entries', 'Effect', 'Impact', 'Func_class', 'Codon_change', 'Aa_change', 'Aa_len', 'Gene_name', 'Biotype', 'Gene_coding', 'Transcript_id', 'Exon_rank', 'Genotype_number', 'Allele', 'Gene', 'Feature', 'Feature_type', 'Consequence', 'Cdna_position', 'Cds_position', 'Protein_position', 'Amino_acids', 'Codons', 'Existing_variation', 'Distance', 'Strand', 'Symbol', 'Symbol_source', 'Sift', 'Polyphen', 'Condel']) for variant in variants: # print 'variant', variant.index writer.writerow([variant.individual, variant.index, variant.pos_index, variant.chr, variant.pos, variant.variant_id, variant.ref, variant.alt, variant.qual, variant.filter, pickle.loads(variant.info), variant.format, variant.genotype_col, variant.genotype, variant.read_depth, variant.gene, variant.mutation_type, variant.vartype, variant.genomes1k_maf, variant.dbsnp_maf, variant.esp_maf, variant.dbsnp_build, variant.sift, variant.sift_pred, variant.polyphen2, variant.polyphen2_pred, variant.condel, variant.condel_pred, variant.dann, variant.cadd, variant.is_at_omim, variant.is_at_hgmd, variant.hgmd_entries]) return response
Example #13
Source File: parse_geoplanet.py From gazetteer with MIT License | 6 votes |
def parse_geoplanet_places_csv(csv_file): csv_reader = csv.reader(open(csv_file, 'rb'), dialect='excel-tab', quoting=csv.QUOTE_NONE) for row in csv_reader: out_line = ['P', row[0], row[1], row[6], row[7], row[8], row[10], row[18]+" 00:00:00+00", "POINT("+row[5]+" "+row[4]+")" ] print "\t".join(out_line) return csv_file #* WOE_ID 0- primary "place" key #* ISO 1- ISO 3166-1 country/territory code #* State 2- WOEID of admin state #* County 3- WOEID of admin county #* Local_Admin 4- WOEID of local admin #* Country 5- WOEID of country #* Continent 6- WOEID of continent
Example #14
Source File: test_csv.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', escapechar='\\') self._write_error_test(csv.Error, ['a',1,'p,"q"'], escapechar=None, doublequote=False) self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar='\\', doublequote = False) self._write_test(['"'], '""""', escapechar='\\', quoting = csv.QUOTE_MINIMAL) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_MINIMAL, doublequote = False) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_NONE) self._write_test(['a',1,'p,q'], 'a,1,p\\,q', escapechar='\\', quoting = csv.QUOTE_NONE)
Example #15
Source File: dialect.py From vnpy_crypto with MIT License | 6 votes |
def test_dialect(self): data = """\ label1,label2,label3 index1,"a,c,e index2,b,d,f """ dia = csv.excel() dia.quoting = csv.QUOTE_NONE with tm.assert_produces_warning(ParserWarning): df = self.read_csv(StringIO(data), dialect=dia) data = '''\ label1,label2,label3 index1,a,c,e index2,b,d,f ''' exp = self.read_csv(StringIO(data)) exp.replace('a', '"a', inplace=True) tm.assert_frame_equal(df, exp)
Example #16
Source File: quoting.py From vnpy_crypto with MIT License | 6 votes |
def test_null_quote_char(self): data = 'a,b,c\n1,2,3' # sanity checks msg = 'quotechar must be set if quoting enabled' tm.assert_raises_regex(TypeError, msg, self.read_csv, StringIO(data), quotechar=None, quoting=csv.QUOTE_MINIMAL) tm.assert_raises_regex(TypeError, msg, self.read_csv, StringIO(data), quotechar='', quoting=csv.QUOTE_MINIMAL) # no errors should be raised if quoting is None expected = DataFrame([[1, 2, 3]], columns=['a', 'b', 'c']) result = self.read_csv(StringIO(data), quotechar=None, quoting=csv.QUOTE_NONE) tm.assert_frame_equal(result, expected) result = self.read_csv(StringIO(data), quotechar='', quoting=csv.QUOTE_NONE) tm.assert_frame_equal(result, expected)
Example #17
Source File: format_runs.py From trec-car-tools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def to_trec_eval_row(self, alternative_exp_name=None, page_only=False): exp_name_ = alternative_exp_name if alternative_exp_name is not None \ else self.exp_name return [self.query_id, 'Q0', self.paragraph_id, self.rank, self.score, exp_name_] # # csv.register_dialect( # 'trec_eval', # delimiter = ' ', # quotechar = '"', # doublequote = False, # skipinitialspace = False, # lineterminator = '\n', # quoting = csv.QUOTE_NONE) # # # def configure_csv_writer(fileobj): # 'Convenience method to create a csv writer with the trec_eval_dialect' # return csv.writer(fileobj, dialect='trec_eval') #
Example #18
Source File: test_csv.py From BinderFilter with MIT License | 6 votes |
def test_write_arg_valid(self): self.assertRaises(csv.Error, self._write_test, None, '') self._write_test((), '') self._write_test([None], '""') self.assertRaises(csv.Error, self._write_test, [None], None, quoting = csv.QUOTE_NONE) # Check that exceptions are passed up the chain class BadList: def __len__(self): return 10; def __getitem__(self, i): if i > 2: raise IOError self.assertRaises(IOError, self._write_test, BadList(), '') class BadItem: def __str__(self): raise IOError self.assertRaises(IOError, self._write_test, [BadItem()], '')
Example #19
Source File: test_csv.py From BinderFilter with MIT License | 6 votes |
def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', escapechar='\\') self.assertRaises(csv.Error, self._write_test, ['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar=None, doublequote=False) self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar='\\', doublequote = False) self._write_test(['"'], '""""', escapechar='\\', quoting = csv.QUOTE_MINIMAL) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_MINIMAL, doublequote = False) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_NONE) self._write_test(['a',1,'p,q'], 'a,1,p\\,q', escapechar='\\', quoting = csv.QUOTE_NONE)
Example #20
Source File: test_csv.py From BinderFilter with MIT License | 6 votes |
def test_quoting(self): class mydialect(csv.Dialect): delimiter = ";" escapechar = '\\' doublequote = False skipinitialspace = True lineterminator = '\r\n' quoting = csv.QUOTE_NONE d = mydialect() mydialect.quoting = None self.assertRaises(csv.Error, mydialect) mydialect.doublequote = True mydialect.quoting = csv.QUOTE_ALL mydialect.quotechar = '"' d = mydialect() mydialect.quotechar = "''" self.assertRaises(csv.Error, mydialect) mydialect.quotechar = 4 self.assertRaises(csv.Error, mydialect)
Example #21
Source File: test_parsers.py From Computable with MIT License | 6 votes |
def test_dialect(self): data = """\ label1,label2,label3 index1,"a,c,e index2,b,d,f """ dia = csv.excel() dia.quoting = csv.QUOTE_NONE df = self.read_csv(StringIO(data), dialect=dia) data = '''\ label1,label2,label3 index1,a,c,e index2,b,d,f ''' exp = self.read_csv(StringIO(data)) exp.replace('a', '"a', inplace=True) tm.assert_frame_equal(df, exp)
Example #22
Source File: test_csv.py From oss-ftp with MIT License | 6 votes |
def test_write_arg_valid(self): self.assertRaises(csv.Error, self._write_test, None, '') self._write_test((), '') self._write_test([None], '""') self.assertRaises(csv.Error, self._write_test, [None], None, quoting = csv.QUOTE_NONE) # Check that exceptions are passed up the chain class BadList: def __len__(self): return 10; def __getitem__(self, i): if i > 2: raise IOError self.assertRaises(IOError, self._write_test, BadList(), '') class BadItem: def __str__(self): raise IOError self.assertRaises(IOError, self._write_test, [BadItem()], '')
Example #23
Source File: test_csv.py From oss-ftp with MIT License | 6 votes |
def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', escapechar='\\') self.assertRaises(csv.Error, self._write_test, ['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar=None, doublequote=False) self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""', escapechar='\\', doublequote = False) self._write_test(['"'], '""""', escapechar='\\', quoting = csv.QUOTE_MINIMAL) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_MINIMAL, doublequote = False) self._write_test(['"'], '\\"', escapechar='\\', quoting = csv.QUOTE_NONE) self._write_test(['a',1,'p,q'], 'a,1,p\\,q', escapechar='\\', quoting = csv.QUOTE_NONE)
Example #24
Source File: test_csv.py From oss-ftp with MIT License | 6 votes |
def test_lineterminator(self): class mydialect(csv.Dialect): delimiter = ";" escapechar = '\\' doublequote = False skipinitialspace = True lineterminator = '\r\n' quoting = csv.QUOTE_NONE d = mydialect() self.assertEqual(d.lineterminator, '\r\n') mydialect.lineterminator = ":::" d = mydialect() self.assertEqual(d.lineterminator, ":::") mydialect.lineterminator = 4 with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), '"lineterminator" must be a string')
Example #25
Source File: pandas_interop.py From ibis with Apache License 2.0 | 6 votes |
def write_csv(self, path): with tempfile.NamedTemporaryFile() as f: # Write the DataFrame to the temporary file path if options.verbose: util.log( 'Writing DataFrame to temporary file {}'.format(f.name) ) self.df.to_csv( f.name, header=False, index=False, sep=',', quoting=csv.QUOTE_NONE, escapechar='\\', na_rep='#NULL', ) f.seek(0) if options.verbose: util.log('Writing CSV to: {0}'.format(path)) self.hdfs.put(path, f.name) return path
Example #26
Source File: index.py From brotab with MIT License | 6 votes |
def index(sqlite_filename, tsv_filename): logger.info('Reading tsv file %s', tsv_filename) # https://stackoverflow.com/questions/15063936/csv-error-field-larger-than-field-limit-131072 # https://github.com/balta2ar/brotab/issues/25 # It should work on Python 3 and Python 2, on any CPU / OS. csv.field_size_limit(int(ctypes.c_ulong(-1).value // 2)) with open(tsv_filename, encoding='utf-8') as tsv_file: lines = [tuple(line) for line in csv.reader(tsv_file, delimiter='\t', quoting=csv.QUOTE_NONE)] logger.info( 'Creating sqlite DB filename %s from tsv %s (%s lines)', sqlite_filename, tsv_filename, len(lines)) conn = sqlite3.connect(sqlite_filename) cursor = conn.cursor() with suppress(sqlite3.OperationalError): cursor.execute('drop table tabs;') cursor.execute( 'create virtual table tabs using fts5(' ' tab_id, title, url, body, tokenize="porter unicode61");') cursor.executemany('insert into tabs values (?, ?, ?, ?)', lines) conn.commit() conn.close()
Example #27
Source File: test_dialect.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_dialect(all_parsers): parser = all_parsers data = """\ label1,label2,label3 index1,"a,c,e index2,b,d,f """ dia = csv.excel() dia.quoting = csv.QUOTE_NONE df = parser.read_csv(StringIO(data), dialect=dia) data = """\ label1,label2,label3 index1,a,c,e index2,b,d,f """ exp = parser.read_csv(StringIO(data)) exp.replace("a", "\"a", inplace=True) tm.assert_frame_equal(df, exp)
Example #28
Source File: test_python_parser_only.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_multi_char_sep_quotes(python_parser_only, quoting): # see gh-13374 kwargs = dict(sep=",,") parser = python_parser_only data = 'a,,b\n1,,a\n2,,"2,,b"' msg = "ignored when a multi-char delimiter is used" def fail_read(): with pytest.raises(ParserError, match=msg): parser.read_csv(StringIO(data), quoting=quoting, **kwargs) if quoting == csv.QUOTE_NONE: # We expect no match, so there should be an assertion # error out of the inner context manager. with pytest.raises(AssertionError): fail_read() else: fail_read()
Example #29
Source File: graphs.py From DOTA_models with Apache License 2.0 | 6 votes |
def _get_vocab_freqs(): """Returns vocab frequencies. Returns: List of integers, length=FLAGS.vocab_size. Raises: ValueError: if the length of the frequency file is not equal to the vocab size, or if the file is not found. """ path = FLAGS.vocab_freq_path or os.path.join(FLAGS.data_dir, 'vocab_freq.txt') if tf.gfile.Exists(path): with tf.gfile.Open(path) as f: # Get pre-calculated frequencies of words. reader = csv.reader(f, quoting=csv.QUOTE_NONE) freqs = [int(row[-1]) for row in reader] if len(freqs) != FLAGS.vocab_size: raise ValueError('Frequency file length %d != vocab size %d' % (len(freqs), FLAGS.vocab_size)) else: if FLAGS.vocab_freq_path: raise ValueError('vocab_freq_path not found') freqs = [1] * FLAGS.vocab_size return freqs
Example #30
Source File: convert.py From spectrify with MIT License | 5 votes |
def __init__(self, sa_table, s3_config, delimiter='|', escapechar='\\', quoting=csv.QUOTE_NONE, unicode_csv=SPECTRIFY_USE_UNICODE_CSV, **kwargs): self.sa_table = sa_table self.s3_config = s3_config self.delimiter = delimiter self.escapechar = escapechar self.quoting = quoting self.unicode_csv = unicode_csv self.kwargs = kwargs