Return whether the provided file is a CSV file or not.
    This checks if the first row of the file can be splitted by ',' and
    if the resulting line contains more than 4 columns (Markers, linkage
    group, chromosome, trait).
165981
def is_csv_file(inputfile):
    
    try:
        stream = open(inputfile)
        row = stream.readline()
    except (IOError, UnicodeDecodeError):  # pragma: no cover
        return False
    finally:
        stream.close()
    content = row.strip().split(',')
    return inputfile.endswith('.csv') and len(content) >= 4
787551
def read_csv_as_integer(csv_name, integer_columns, usecols=None):
    
    csv_path = os.path.join(DATA_FOLDER, csv_name)
    csv = pd.read_csv(csv_path, low_memory=False, usecols=usecols)
    for column in integer_columns:
        csv = csv[pd.to_numeric(csv[column], errors="coerce").notnull()]
    csv[integer_columns] = csv[integer_columns].apply(pd.to_numeric)
    return csv
1259285
def read_csv_with_different_type(csv_name, column_types_dict, usecols=None):
    
    csv_path = os.path.join(DATA_FOLDER, csv_name)
    csv = pd.read_csv(
        csv_path,
        usecols=usecols,
        encoding="utf-8",
        dtype=column_types_dict,
        engine="python",
    )

    for key_column, val_type in column_types_dict.items():
        if val_type == str:
            csv[key_column] = csv[key_column].str.strip()

    return csv
904331
def read_csv(filename, delimiter=CSV_DELIMITER):
    
    with open(filename, 'r') as file:
        return list(csv.reader(file, delimiter=delimiter))
230519
def is_file(cls, file):
        ''''''
        peeked_data = wpull.string.printable_bytes(
            wpull.util.peek_file(file)).lower()

        if b'<html' in peeked_data:
            return VeryFalse

        if re.search(br'@import |color:|background[a-z-]*:|font[a-z-]*:',
                     peeked_data):
            return True
1200085
def _ReadCsvDict(self, file_name, cols, required, deprecated):
    """"""
    assert file_name.endswith(".txt")
    table_name = file_name[0:-4]
    contents = self._GetUtf8Contents(file_name)
    if not contents:
      return

    eol_checker = util.EndOfLineChecker(StringIO.StringIO(contents),
                                   file_name, self._problems)
    # The csv module doesn't provide a way to skip trailing space, but when I
    # checked 15/675 feeds had trailing space in a header row and 120 had spaces
    # after fields. Space after header fields can cause a serious parsing
    # problem, so warn. Space after body fields can cause a problem time,
    # integer and id fields; they will be validated at higher levels.
    reader = csv.reader(eol_checker, skipinitialspace=True)

    raw_header = next(reader)
    header_occurrences = util.defaultdict(lambda: 0)
    header = []
    valid_columns = []  # Index into raw_header and raw_row
    for i, h in enumerate(raw_header):
      h_stripped = h.strip()
      if not h_stripped:
        self._problems.CsvSyntax(
            description="The header row should not contain any blank values. "
                        "The corresponding column will be skipped for the "
                        "entire file.",
            context=(file_name, 1, [''] * len(raw_header), raw_header),
            type=problems.TYPE_ERROR)
        continue
      elif h != h_stripped:
        self._problems.CsvSyntax(
            description="The header row should not contain any "
                        "space characters.",
            context=(file_name, 1, [''] * len(raw_header), raw_header),
            type=problems.TYPE_WARNING)
      header.append(h_stripped)
      valid_columns.append(i)
      header_occurrences[h_stripped] += 1

    for name, count in header_occurrences.items():
      if count > 1:
        self._problems.DuplicateColumn(
            header=name,
            file_name=file_name,
            count=count)

    self._schedule._table_columns[table_name] = header

    # check for unrecognized columns, which are often misspellings
    header_context = (file_name, 1, [''] * len(header), header)
    valid_cols = cols + [deprecated_name for (deprecated_name, _) in deprecated]
    unknown_cols = set(header) - set(valid_cols)
    if len(unknown_cols) == len(header):
      self._problems.CsvSyntax(
            description="The header row did not contain any known column "
                        "names. The file is most likely missing the header row "
                        "or not in the expected CSV format.",
            context=(file_name, 1, [''] * len(raw_header), raw_header),
            type=problems.TYPE_ERROR)
    else:
      for col in unknown_cols:
        # this is provided in order to create a nice colored list of
        # columns in the validator output
        self._problems.UnrecognizedColumn(file_name, col, header_context)

    # check for missing required columns
    missing_cols = set(required) - set(header)
    for col in missing_cols:
      # this is provided in order to create a nice colored list of
      # columns in the validator output
      self._problems.MissingColumn(file_name, col, header_context)

    # check for deprecated columns
    for (deprecated_name, new_name) in deprecated:
      if deprecated_name in header:
        self._problems.DeprecatedColumn(file_name, deprecated_name, new_name,
                                        header_context)

    line_num = 1  # First line read by reader.next() above
    for raw_row in reader:
      line_num += 1
      if len(raw_row) == 0:  # skip extra empty lines in file
        continue

      if len(raw_row) > len(raw_header):
        self._problems.OtherProblem('Found too many cells (commas) in line '
                                    '%d of file "%s".  Every row in the file '
                                    'should have the same number of cells as '
                                    'the header (first line) does.' %
                                    (line_num, file_name),
                                    (file_name, line_num),
                                    type=problems.TYPE_WARNING)

      if len(raw_row) < len(raw_header):
        self._problems.OtherProblem('Found missing cells (commas) in line '
                                    '%d of file "%s".  Every row in the file '
                                    'should have the same number of cells as '
                                    'the header (first line) does.' %
                                    (line_num, file_name),
                                    (file_name, line_num),
                                    type=problems.TYPE_WARNING)

      # raw_row is a list of raw bytes which should be valid utf-8. Convert each
      # valid_columns of raw_row into Unicode.
      valid_values = []
      unicode_error_columns = []  # index of valid_values elements with an error
      for i in valid_columns:
        try:
          valid_values.append(raw_row[i].decode('utf-8'))
        except UnicodeDecodeError:
          # Replace all invalid characters with REPLACEMENT CHARACTER (U+FFFD)
          valid_values.append(codecs.getdecoder("utf8")
                              (raw_row[i], errors="replace")[0])
          unicode_error_columns.append(len(valid_values) - 1)
        except IndexError:
          break

      # The error report may contain a dump of all values in valid_values so
      # problems can not be reported until after converting all of raw_row to
      # Unicode.
      for i in unicode_error_columns:
        self._problems.InvalidValue(header[i], valid_values[i],
                                    'Unicode error',
                                    (file_name, line_num,
                                     valid_values, header))

      # We strip ALL whitespace from around values.  This matches the behavior
      # of both the Google and OneBusAway GTFS parser.
      valid_values = [value.strip() for value in valid_values]

      d = dict(zip(header, valid_values))
      yield (d, line_num, header, valid_values)
1199420
def _CheckIsFile(self, file_entry):
    
    if definitions.FILE_ENTRY_TYPE_FILE not in self._file_entry_types:
      return False
    return file_entry.IsFile()
7563
def identify_sep(filepath):
    
    ext = os.path.splitext(filepath)[1].lower()
    allowed_exts = ['.csv', '.txt', '.tsv']
    assert ext in ['.csv', '.txt'], "Unexpected file extension {}. \
                                    Supported extensions {}\n filename: {}".format(
                                    ext, allowed_exts, os.path.basename(filepath))
    maybe_seps = ['|',
                  ';',
                  ',',
                  '\t',
                  ':']

    with open(filepath,'r') as fp:
        header = fp.__next__()

    count_seps_header = {sep: _count(sep, header) for sep in maybe_seps}
    count_seps_header = {sep: count for sep,
                         count in count_seps_header.items() if count > 0}

    if count_seps_header:
        return max(count_seps_header.__iter__(),
                   key=(lambda key: count_seps_header[key]))
    else:
        raise Exception("Couldn't identify the sep from the header... here's the information:\n HEADER: {}\n SEPS SEARCHED: {}".format(header, maybe_seps))
950560
public byte[] getContents(FileColumn[] columns, List<String[]> lines)
        throws IOException
    {
        byte[] ret;

        // Excel spreadsheet
        if(format.isExcel())
        {
            ret = getExcelOutput(columns, lines);
        }
        else // Assume it's a CSV file
        {
            ret = getCSVOutput(lines);
        }

        return ret;
    }
934980
def guess_lineno(file):
    
    offset = file.tell()
    file.seek(0)
    startpos = 0
    lineno = 1
    # looks like file.read() return bytes in python3
    # so I need more complicated algorithm here
    while True:
        line = file.readline()
        if not line:
            break
        endpos = file.tell()
        if startpos <= offset < endpos:
            break
        lineno += 1
    file.seek(offset)
    return lineno
531898
def isglove(filepath):
    

    with ensure_open(filepath, 'r') as f:
        header_line = f.readline()
        vector_line = f.readline()
    try:
        num_vectors, num_dim = header_line.split()
        return int(num_dim)
    except (ValueError, TypeError):
        pass
    vector = vector_line.split()[1:]
    if len(vector) % 10:
        print(vector)
        print(len(vector) % 10)
        return False
    try:
        vector = np.array([float(x) for x in vector])
    except (ValueError, TypeError):
        return False
    if np.all(np.abs(vector) < 12.):
        return len(vector)
    return False
69897
@Pure
	public static boolean isDbaseFile(File file) {
		return FileType.isContentType(
				file,
				MimeName.MIME_DBASE_FILE.getMimeConstant());
	}
1325820
def csv(ticker, path='data.csv', field='', mrefresh=False, **kwargs):
    
    # set defaults if not specified
    if 'index_col' not in kwargs:
        kwargs['index_col'] = 0
    if 'parse_dates' not in kwargs:
        kwargs['parse_dates'] = True

    # read in dataframe from csv file
    df = pd.read_csv(path, **kwargs)

    tf = ticker
    if field is not '' and field is not None:
        tf = '%s:%s' % (tf, field)

    # check that required column exists
    if tf not in df:
        raise ValueError('Ticker(field) not present in csv file!')

    return df[tf]
935209
def is_binary(filename):
    
    logger.debug('is_binary: %(filename)r', locals())

    # Check if the file extension is in a list of known binary types
    binary_extensions = ['pyc', 'iso', 'zip', 'pdf']
    for ext in binary_extensions:
        if filename.endswith(ext):
            return True

    # Check if the starting chunk is a binary string
    chunk = get_starting_chunk(filename)
    return is_binary_string(chunk)
1291027
def _read_csv_lines(path):
    
    csv_file = open(path, 'r')
    csv_lines_raw = csv_file.readlines()
    csv_lines_clean = [line for line in csv_lines_raw if len(line.strip()) > 0]
    return csv_lines_clean
1035238
def is_splitter(line):
    '''
    
    '''
    for pattern in SPLITTER_PATTERNS:
        matcher = re.match(pattern, line)
        if matcher:
            return matcher
661934
def read_csv(csvfile, options):
    

    # open file or exit
    name, ext = os.path.splitext(csvfile)
    try:
        if ext == '.gz':
            f = gzip.open(csvfile, 'rb')
        else:
            f = open(csvfile, 'rU')
    except IOError:
        print(" \n '{f}' could not be opened\n".format(f=os.path.basename(csvfile)))
        sys.exit(1)

    # read file
    csv_reader = csv.reader(f)
    molList = []
    linenumber = 1

    for line in csv_reader:
        # get column labels from the first line
        if linenumber == 1:
            prop_indices = read_header(line, options)

        # otherwise read line & append to MolList
        else:
            mol = Molecule()
            mol = read_line(line, options, prop_indices, mol)
            # if the line's junk, skip it
            if mol == 1:
                print(" skipping molecule 'm'\n".format(m=(linenumber - 1)))
            else:
                molList.append(mol)

        linenumber += 1

    # return molList

    return molList