class_docstr: Load FeatureSets from files on disk.
  
  This is the base class used to create featureset readers for different
  file types.
  
  Parameters
  ----------
  path_or_list : Union[:class:`skll.types.PathOrStr`, List[Dict[str, Any]]
      Path or a list of example dictionaries.
  
  quiet : bool, default=True
      Do not print "Loading..." status message to stderr.
  
  ids_to_floats : bool, default=False
      Convert IDs to float to save memory. Will raise error
      if we encounter an a non-numeric ID.
  
  label_col : Optional[str], default='y'
      Name of the column which contains the class labels
      for ARFF/CSV/TSV files. If no column with that name
      exists, or ``None`` is specified, the data is
      considered to be unlabelled.
  
  id_col : str, default='id'
      Name of the column which contains the instance IDs.
      If no column with that name exists, or ``None`` is
      specified, example IDs will be automatically generated.
  
  class_map : Optional[:class:`skll.types.ClassMap`], default=None
      Mapping from original class labels to new ones. This is
      mainly used for collapsing multiple labels into a single
      class. Anything not in the mapping will be kept the same.
      The keys are the new labels and the list of values for each
      key is the labels to be collapsed to said new label.
  
  sparse : bool, default=True
      Whether or not to store the features in a numpy CSR
      matrix when using a DictVectorizer to vectorize the
      features.
  
  feature_hasher : bool, default=False
      Whether or not a FeatureHasher should be used to
      vectorize the features.
  
  num_features : Optional[int], default=None
      If using a FeatureHasher, how many features should the
      resulting matrix have?  You should set this to a power
      of 2 greater than the actual number of features to
      avoid collisions.
  
  logger : Optional[logging.Logger], default=None
      A logger instance to use to log messages instead of creating
      a new one by default.
class_docstr_tok: ["Load","FeatureSets","from","files","on","disk",".","This","is","the","base","class","used","to","create","featureset","readers","for","different","file","types",".","Parameters","--","--","--","--","--","path_or_list",":","Union","[",":","class",":","`","skll.types.PathOrStr","`",",","List","[","Dict","[","str",",","Any","]","]","Path","or","a","list","of","example","dictionaries",".","quiet",":","bool",",","default=True","Do","not","print","``","Loading","...","''","status","message","to","stderr",".","ids_to_floats",":","bool",",","default=False","Convert","IDs","to","float","to","save","memory",".","Will","raise","error","if","we","encounter","an","a","non-numeric","ID",".","label_col",":","Optional","[","str","]",",","default=","'","y'","Name","of","the","column","which","contains","the","class","labels","for","ARFF\/CSV\/TSV","files",".","If","no","column","with","that","name","exists",",","or","``","None","``","is","specified",",","the","data","is","considered","to","be","unlabelled",".","id_col",":","str",",","default='id'","Name","of","the","column","which","contains","the","instance","IDs",".","If","no","column","with","that","name","exists",",","or","``","None","``","is","specified",",","example","IDs","will","be","automatically","generated",".","class_map",":","Optional","[",":","class",":","`","skll.types.ClassMap","`","]",",","default=None","Mapping","from","original","class","labels","to","new","ones",".","This","is","mainly","used","for","collapsing","multiple","labels","into","a","single","class",".","Anything","not","in","the","mapping","will","be","kept","the","same",".","The","keys","are","the","new","labels","and","the","list","of","values","for","each","key","is","the","labels","to","be","collapsed","to","said","new","label",".","sparse",":","bool",",","default=True","Whether","or","not","to","store","the","features","in","a","numpy","CSR","matrix","when","using","a","DictVectorizer","to","vectorize","the","features",".","feature_hasher",":","bool",",","default=False","Whether","or","not","a","FeatureHasher","should","be","used","to","vectorize","the","features",".","num_features",":","Optional","[","int","]",",","default=None","If","using","a","FeatureHasher",",","how","many","features","should","the","resulting","matrix","have","?","You","should","set","this","to","a","power","of","2","greater","than","the","actual","number","of","features","to","avoid","collisions",".","logger",":","Optional","[","logging.Logger","]",",","default=None","A","logger","instance","to","use","to","log","messages","instead","of","creating","a","new","one","by","default","."]
docstr: Read the file in row-by-row.
  
  This method is used for ``Reader`` objects that do not rely on ``pandas``,
  and are instead read line-by-line into a FeatureSet object, unlike
  pandas-based reader object, which will read everything into memory in
  a data frame object before converting to a ``FeatureSet``.
  
  Parameters
  ----------
  file : :class:`skll.types.PathOrStr`
      The path to the input file.
  
  Returns
  -------
  ids : numpy.ndarray of shape (n_ids,)
      The ids array.
  
  labels : numpy.ndarray of shape (n_labels,)
      The labels array.
  
  features : :class:`skll.types.FeatureDictList`
      List containing feature dictionaries.
  
  Raises
  ------
  ValueError
      If ``ids_to_floats`` is True, but IDs cannot be converted.
  
  ValueError
      If no features are found.
  
  ValueError
      If the example IDs are not unique.
docstr_tok: ["Read","the","file","in","row-by-row",".","This","method","is","used","for","``","Reader","``","objects","that","do","not","rely","on","``","pandas","``",",","and","are","instead","read","line-by-line","into","a","FeatureSet","object",",","unlike","pandas-based","reader","object",",","which","will","read","everything","into","memory","in","a","data","frame","object","before","converting","to","a","``","FeatureSet","``",".","Parameters","--","--","--","--","--","file",":",":","class",":","`","skll.types.PathOrStr","`","The","path","to","the","input","file",".","Returns","--","--","--","-","ids",":","numpy.ndarray","of","shape","(","n_ids",",",")","The","ids","array",".","labels",":","numpy.ndarray","of","shape","(","n_labels",",",")","The","labels","array",".","features",":",":","class",":","`","skll.types.FeatureDictList","`","List","containing","feature","dictionaries",".","Raises","--","--","--","ValueError","If","``","ids_to_floats","``","is","True",",","but","IDs","can","not","be","converted",".","ValueError","If","no","features","are","found",".","ValueError","If","the","example","IDs","are","not","unique","."]
code: def _sub_read_rows(
      self, file: PathOrStr
  ) -> Tuple[np.ndarray, np.ndarray, FeatureDictList]:
      """
      Read the file in row-by-row.
  
      This method is used for ``Reader`` objects that do not rely on ``pandas``,
      and are instead read line-by-line into a FeatureSet object, unlike
      pandas-based reader object, which will read everything into memory in
      a data frame object before converting to a ``FeatureSet``.
  
      Parameters
      ----------
      file : :class:`skll.types.PathOrStr`
          The path to the input file.
  
      Returns
      -------
      ids : numpy.ndarray of shape (n_ids,)
          The ids array.
  
      labels : numpy.ndarray of shape (n_labels,)
          The labels array.
  
      features : :class:`skll.types.FeatureDictList`
          List containing feature dictionaries.
  
      Raises
      ------
      ValueError
          If ``ids_to_floats`` is True, but IDs cannot be converted.
  
      ValueError
          If no features are found.
  
      ValueError
          If the example IDs are not unique.
      """
      # Get labels and IDs
      ids_list: List[IdType] = []
      labels_list: List[LabelType] = []
      ex_num = 0
      with open(file, encoding="utf-8") as f:
          for ex_num, (id_, class_, _) in enumerate(
              self._sub_read(f), start=1
          ):
              # Update lists of IDs, classes, and features
              if self.ids_to_floats:
                  try:
                      id_ = float(id_)
                  except ValueError:
                      raise ValueError(
                          "You set ids_to_floats to true, but "
                          f"ID {id_} could not be converted to"
                          f" float in {self.path_or_list}"
                      )
              ids_list.append(id_)
              labels_list.append(class_)
              if ex_num % 100 == 0:
                  self._print_progress(ex_num)
          self._print_progress(ex_num)
  
      # Remember total number of examples for percentage progress meter
      total = ex_num
      if total == 0:
          raise ValueError(
              "No features found in possibly empty file "
              f"'{self.path_or_list}'."
          )
  
      # Convert everything to numpy arrays
      ids = np.array(ids_list)
      labels = np.array(labels_list)
  
      def feat_dict_generator():
          with open(self.path_or_list, encoding="utf-8") as f:
              for ex_num, (_, _, feat_dict) in enumerate(
                  self._sub_read(f)
              ):
                  yield feat_dict
                  if ex_num % 100 == 0:
                      self._print_progress(
                          f"{100 * ex_num / total:.8}%"
                      )
              self._print_progress("100%")
  
      # extract the features dictionary
      features = feat_dict_generator()
  
      return ids, labels, features
  
imports: import csv
  import json
  import logging
  import re
  import sys
  from io import StringIO
  from itertools import chain
  from numbers import Number
  from pathlib import Path
  from typing import IO, Any, Dict, List, Optional, Tuple, Union
  import numpy
  import pandas
  from bs4 import UnicodeDammit
  from sklearn.feature_extraction import FeatureHasher
  from skll.data import FeatureSet
  from skll.data.dict_vectorizer import DictVectorizer
  from skll.types import ClassMap, FeatGenerator, FeatureDictList, IdType, LabelType, PathOrStr
label_desc: Use image node_id 5 for calling the Reader obj's underlying member method code with example usage: obj._sub_read_rows(file) and returns: ids,  labels,  features