class_docstr: An :class:`NAAction` object defines a strategy for handling missing
  data.
  
  "NA" is short for "Not Available", and is used to refer to any value which
  is somehow unmeasured or unavailable. In the long run, it is devoutly
  hoped that numpy will gain first-class missing value support. Until then,
  we work around this lack as best we're able.
  
  There are two parts to this: First, we have to determine what counts as
  missing data. For numerical data, the default is to treat NaN values
  (e.g., ``numpy.nan``) as missing. For categorical data, the default is to
  treat NaN values, and also the Python object None, as missing. (This is
  consistent with how pandas does things, so if you're already using
  None/NaN to mark missing data in your pandas DataFrames, you're good to
  go.)
  
  Second, we have to decide what to do with any missing data when we
  encounter it. One option is to simply discard any rows which contain
  missing data from our design matrices (``drop``). Another option is to
  raise an error (``raise``). A third option would be to simply let the
  missing values pass through into the returned design matrices. However,
  this last option is not yet implemented, because of the lack of any
  standard way to represent missing values in arbitrary numpy matrices;
  we're hoping numpy will get this sorted out before we standardize on
  anything ourselves.
  
  You can control how patsy handles missing data through the ``NA_action=``
  argument to functions like :func:`build_design_matrices` and
  :func:`dmatrix`. If all you want to do is to choose between ``drop`` and
  ``raise`` behaviour, you can pass one of those strings as the
  ``NA_action=`` argument directly. If you want more fine-grained control
  over how missing values are detected and handled, then you can create an
  instance of this class, or your own object that implements the same
  interface, and pass that as the ``NA_action=`` argument instead.
class_docstr_tok: ["An",":","class",":","`","NAAction","`","object","defines","a","strategy","for","handling","missing","data",".","``","NA","''","is","short","for","``","Not","Available","''",",","and","is","used","to","refer","to","any","value","which","is","somehow","unmeasured","or","unavailable",".","In","the","long","run",",","it","is","devoutly","hoped","that","numpy","will","gain","first-class","missing","value","support",".","Until","then",",","we","work","around","this","lack","as","best","we","'re","able",".","There","are","two","parts","to","this",":","First",",","we","have","to","determine","what","counts","as","missing","data",".","For","numerical","data",",","the","default","is","to","treat","NaN","values","(","e.g.",",","``","numpy.nan","``",")","as","missing",".","For","categorical","data",",","the","default","is","to","treat","NaN","values",",","and","also","the","Python","object","None",",","as","missing",".","(","This","is","consistent","with","how","pandas","does","things",",","so","if","you","'re","already","using","None\/NaN","to","mark","missing","data","in","your","pandas","DataFrames",",","you","'re","good","to","go",".",")","Second",",","we","have","to","decide","what","to","do","with","any","missing","data","when","we","encounter","it",".","One","option","is","to","simply","discard","any","rows","which","contain","missing","data","from","our","design","matrices","(","``","drop","``",")",".","Another","option","is","to","raise","an","error","(","``","raise","``",")",".","A","third","option","would","be","to","simply","let","the","missing","values","pass","through","into","the","returned","design","matrices",".","However",",","this","last","option","is","not","yet","implemented",",","because","of","the","lack","of","any","standard","way","to","represent","missing","values","in","arbitrary","numpy","matrices",";","we","'re","hoping","numpy","will","get","this","sorted","out","before","we","standardize","on","anything","ourselves",".","You","can","control","how","patsy","handles","missing","data","through","the","``","NA_action=","``","argument","to","functions","like",":","func",":","`","build_design_matrices","`","and",":","func",":","`","dmatrix","`",".","If","all","you","want","to","do","is","to","choose","between","``","drop","``","and","``","raise","``","behaviour",",","you","can","pass","one","of","those","strings","as","the","``","NA_action=","``","argument","directly",".","If","you","want","more","fine-grained","control","over","how","missing","values","are","detected","and","handled",",","then","you","can","create","an","instance","of","this","class",",","or","your","own","object","that","implements","the","same","interface",",","and","pass","that","as","the","``","NA_action=","``","argument","instead","."]
docstr: Takes a set of factor values that may have NAs, and handles them
  appropriately.
  
  :arg values: A list of `ndarray` objects representing the data.
    These may be 1- or 2-dimensional, and may be of varying dtype. All
    will have the same number of rows (or entries, for 1-d arrays).
  :arg is_NAs: A list with the same number of entries as `values`,
    containing boolean `ndarray` objects that indicate which rows
    contain NAs in the corresponding entry in `values`.
  :arg origins: A list with the same number of entries as
    `values`, containing information on the origin of each
    value. If we encounter a problem with some particular value, we use
    the corresponding entry in `origins` as the origin argument when
    raising a :class:`PatsyError`.
  :returns: A list of new values (which may have a differing number of
    rows.)
docstr_tok: ["Takes","a","set","of","factor","values","that","may","have","NAs",",","and","handles","them","appropriately",".",":","arg","values",":","A","list","of","`","ndarray","`","objects","representing","the","data",".","These","may","be","1-","or","2-dimensional",",","and","may","be","of","varying","dtype",".","All","will","have","the","same","number","of","rows","(","or","entries",",","for","1-d","arrays",")",".",":","arg","is_NAs",":","A","list","with","the","same","number","of","entries","as","`","values","`",",","containing","boolean","`","ndarray","`","objects","that","indicate","which","rows","contain","NAs","in","the","corresponding","entry","in","`","values","`",".",":","arg","origins",":","A","list","with","the","same","number","of","entries","as","`","values","`",",","containing","information","on","the","origin","of","each","value",".","If","we","encounter","a","problem","with","some","particular","value",",","we","use","the","corresponding","entry","in","`","origins","`","as","the","origin","argument","when","raising","a",":","class",":","`","PatsyError","`",".",":","returns",":","A","list","of","new","values","(","which","may","have","a","differing","number","of","rows",".",")"]
code: def handle_NA(self, values, is_NAs, origins):
      """Takes a set of factor values that may have NAs, and handles them
      appropriately.
  
      :arg values: A list of `ndarray` objects representing the data.
        These may be 1- or 2-dimensional, and may be of varying dtype. All
        will have the same number of rows (or entries, for 1-d arrays).
      :arg is_NAs: A list with the same number of entries as `values`,
        containing boolean `ndarray` objects that indicate which rows
        contain NAs in the corresponding entry in `values`.
      :arg origins: A list with the same number of entries as
        `values`, containing information on the origin of each
        value. If we encounter a problem with some particular value, we use
        the corresponding entry in `origins` as the origin argument when
        raising a :class:`PatsyError`.
      :returns: A list of new values (which may have a differing number of
        rows.)
      """
      assert len(values) == len(is_NAs) == len(origins)
      if len(values) == 0:
          return values
      if self.on_NA == "raise":
          return self._handle_NA_raise(values, is_NAs, origins)
      elif self.on_NA == "drop":
          return self._handle_NA_drop(values, is_NAs, origins)
      else:  # pragma: no cover
          assert False
  
file_path: patsy/patsy/missing.py
imports: import numpy
  from patsy import PatsyError
  from patsy.util import safe_isnan, safe_scalar_isnan, no_pickling, assert_no_pickling
label_desc: Use image node_id 4 for calling the NAAction obj's underlying member method code with example usage: obj.handle_NA(values, is_NAs, origins) and returns: values, self, self