class_docstr: Creates `Dataset` objects from input CSV files.
  
  This class provides conveniences to load data from CSV files.
  It's possible to directly featurize data from CSV files using
  pandas, but this class may prove useful if you're processing
  large CSV files that you don't want to manipulate directly in
  memory. Note that samples which cannot be featurized are filtered
  out in the creation of final dataset.
  
  Examples
  --------
  Let's suppose we have some smiles and labels
  
  >>> smiles = ["C", "CCC"]
  >>> labels = [1.5, 2.3]
  
  Let's put these in a dataframe.
  
  >>> import pandas as pd
  >>> df = pd.DataFrame(list(zip(smiles, labels)), columns=["smiles", "task1"])
  
  Let's now write this to disk somewhere. We can now use `CSVLoader` to
  process this CSV dataset.
  
  >>> import tempfile
  >>> import deepchem as dc
  >>> with dc.utils.UniversalNamedTemporaryFile(mode='w') as tmpfile:
  ...     df.to_csv(tmpfile.name)
  ...     loader = dc.data.CSVLoader(["task1"], feature_field="smiles",
  ...                              featurizer=dc.feat.CircularFingerprint())
  ...     dataset = loader.create_dataset(tmpfile.name)
  >>> len(dataset)
  2
  
  Of course in practice you should already have your data in a CSV file if
  you're using `CSVLoader`. If your data is already in memory, use
  `InMemoryLoader` instead.
  
  Sometimes there will be datasets without specific tasks, for example
  datasets which are used in unsupervised learning tasks. Such datasets
  can be loaded by leaving the `tasks` field empty.
  
  Example
  -------
  
  >>> x1, x2 = [2, 3, 4], [4, 6, 8]
  >>> df = pd.DataFrame({"x1":x1, "x2": x2}).reset_index()
  >>> with dc.utils.UniversalNamedTemporaryFile(mode='w') as tmpfile:
  ...     df.to_csv(tmpfile.name)
  ...     loader = dc.data.CSVLoader(tasks=[], id_field="index", feature_field=["x1", "x2"],
  ...                              featurizer=dc.feat.DummyFeaturizer())
  ...     dataset = loader.create_dataset(tmpfile.name)
  >>> len(dataset)
  3
class_docstr_tok: ["Creates","`","Dataset","`","objects","from","input","CSV","files",".","This","class","provides","conveniences","to","load","data","from","CSV","files",".","It","'s","possible","to","directly","featurize","data","from","CSV","files","using","pandas",",","but","this","class","may","prove","useful","if","you","'re","processing","large","CSV","files","that","you","do","n't","want","to","manipulate","directly","in","memory",".","Note","that","samples","which","can","not","be","featurized","are","filtered","out","in","the","creation","of","final","dataset",".","Examples","--","--","--","--","Let","'s","suppose","we","have","some","smiles","and","labels",">",">",">","smiles","=","[","``","C","''",",","``","CCC","''","]",">",">",">","labels","=","[","1.5",",","2.3","]","Let","'s","put","these","in","a","dataframe",".",">",">",">","import","pandas","as","pd",">",">",">","df","=","pd.DataFrame","(","list","(","zip","(","smiles",",","labels",")",")",",","columns=","[","``","smiles","''",",","``","task1","''","]",")","Let","'s","now","write","this","to","disk","somewhere",".","We","can","now","use","`","CSVLoader","`","to","process","this","CSV","dataset",".",">",">",">","import","tempfile",">",">",">","import","deepchem","as","dc",">",">",">","with","dc.utils.UniversalNamedTemporaryFile","(","mode=","'","w","'",")","as","tmpfile",":","...","df.to_csv","(","tmpfile.name",")","...","loader","=","dc.data.CSVLoader","(","[","``","task1","''","]",",","feature_field=","''","smiles","''",",","...","featurizer=dc.feat.CircularFingerprint","(",")",")","...","dataset","=","loader.create_dataset","(","tmpfile.name",")",">",">",">","len","(","dataset",")","2","Of","course","in","practice","you","should","already","have","your","data","in","a","CSV","file","if","you","'re","using","`","CSVLoader","`",".","If","your","data","is","already","in","memory",",","use","`","InMemoryLoader","`","instead",".","Sometimes","there","will","be","datasets","without","specific","tasks",",","for","example","datasets","which","are","used","in","unsupervised","learning","tasks",".","Such","datasets","can","be","loaded","by","leaving","the","`","tasks","`","field","empty",".","Example","--","--","--","-",">",">",">","x1",",","x2","=","[","2",",","3",",","4","]",",","[","4",",","6",",","8","]",">",">",">","df","=","pd.DataFrame","(","{","``","x1","''",":","x1",",","``","x2","''",":","x2","}",")",".reset_index","(",")",">",">",">","with","dc.utils.UniversalNamedTemporaryFile","(","mode=","'","w","'",")","as","tmpfile",":","...","df.to_csv","(","tmpfile.name",")","...","loader","=","dc.data.CSVLoader","(","tasks=","[","]",",","id_field=","''","index","''",",","feature_field=","[","``","x1","''",",","``","x2","''","]",",","...","featurizer=dc.feat.DummyFeaturizer","(",")",")","...","dataset","=","loader.create_dataset","(","tmpfile.name",")",">",">",">","len","(","dataset",")","3"]
docstr: Featurizes a shard of an input dataframe.
  
  Parameters
  ----------
  shard: pd.DataFrame
      DataFrame that holds a shard of the input CSV file
  
  Returns
  -------
  features: np.ndarray
      Features computed from CSV file.
  valid_inds: np.ndarray
      Indices of rows in source CSV with valid data.
docstr_tok: ["Featurizes","a","shard","of","an","input","dataframe",".","Parameters","--","--","--","--","--","shard",":","pd.DataFrame","DataFrame","that","holds","a","shard","of","the","input","CSV","file","Returns","--","--","--","-","features",":","np.ndarray","Features","computed","from","CSV","file",".","valid_inds",":","np.ndarray","Indices","of","rows","in","source","CSV","with","valid","data","."]
code: def _featurize_shard(
      self, shard: pd.DataFrame
  ) -> Tuple[np.ndarray, np.ndarray]:
      """Featurizes a shard of an input dataframe.
  
      Parameters
      ----------
      shard: pd.DataFrame
          DataFrame that holds a shard of the input CSV file
  
      Returns
      -------
      features: np.ndarray
          Features computed from CSV file.
      valid_inds: np.ndarray
          Indices of rows in source CSV with valid data.
      """
      logger.info("About to featurize shard.")
      if self.featurizer is None:
          raise ValueError(
              "featurizer must be specified in constructor to featurizer data/"
          )
      features = [
          elt for elt in self.featurizer(shard[self.feature_field])
      ]
      valid_inds = np.array(
          [1 if np.array(elt).size > 0 else 0 for elt in features],
          dtype=bool,
      )
      features = [
          elt
          for (is_valid, elt) in zip(valid_inds, features)
          if is_valid
      ]
      return np.array(features), valid_inds
  
imports: import os
  import tempfile
  import zipfile
  import time
  import logging
  import warnings
  from typing import List, Optional, Tuple, Any, Sequence, Union, Iterator
  import pandas
  import numpy
  from deepchem.utils.typing import OneOrMany
  from deepchem.utils.data_utils import load_image_files, load_csv_files, load_json_files, load_sdf_files, unzip_file
  from deepchem.feat import UserDefinedFeaturizer, Featurizer
  from deepchem.data import Dataset, DiskDataset, NumpyDataset, ImageDataset
  from deepchem.feat.molecule_featurizers import OneHotFeaturizer
  from deepchem.utils.genomics_utils import encode_bio_sequence
label_desc: Use image node_id 3 for calling the CSVLoader obj's underlying member method code with example usage: obj._featurize_shard(shard) and returns: np,  valid_inds