{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "dev:api-dev:nan_policy",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Many functions in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.stats",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.stats"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " have a parameter called "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " that determines how the function handles data that contains "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  In this section, we provide SciPy developer guidelines for how "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is intended to be used, to ensure that as this parameter is added to new functions, we maintain a consistent API."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "A Design Specification for "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "nan_policy"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The parameter "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " accepts three possible strings: "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'omit'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'raise'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "'propagate'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  The meanings are:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan_policy='omit'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ":   Ignore occurrences of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the input.  Do not generate a warning   if the input contains "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (unless the equivalent input with the   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values removed would generate a warning). For example, for the   simple case of a function that accepts a single array and returns a   scalar (and ignoring the possible use of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for the moment)        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func([1.0, 3.0, np.nan, 5.0], nan_policy='omit')",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "should behave the same as        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func([1.0, 3.0, 5.0])",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "More generally, for functions that return a scalar,   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "func(a, nan_policy='omit')"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " should behave the same as   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "func(a[~np.isnan(a)])"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For functions that transform a vector to a new vector of the same   size and for which each entry in the output array depends on   more than just the corresponding value in the input array "
                    },
                    {
                      "__type": "FootnoteReference",
                      "__tag": 4066,
                      "label": "1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (e.g.   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.zscore",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._stats_py:zscore"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.boxcox",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._morestats:boxcox"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "when"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lmbda"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "is None"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "),        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "y = func(a, nan_policy='omit')",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "should behave the same as        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "nan_mask = np.isnan(a)\ny = np.empty(a.shape, dtype=np.float64)\ny[~nan_mask] = func(a[~nan_mask])\ny[nan_mask] = np.nan",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "(In general, the dtype of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " might depend on "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and on the expected   behavior of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ").  In other words, a "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "nan",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the input gives a   corresponding "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "nan",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the output, but the presence of that "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "nan",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " does not   affect the calculation of the non-"
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "nan",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Unit tests for this property should be used to test functions that   handle "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan_policy"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For functions that return a scalar and that accept two or more arguments   but whose values are not related (e.g. "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.ansari",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._morestats:ansari"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.f_oneway",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._stats_py:f_oneway"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "), the same idea applies to each input array.  So        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func(a, b, nan_policy='omit')",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "should behave the same as        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func(a[~np.isnan(a)], b[~np.isnan(b)])",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For inputs with "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "related"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "paired"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values (e.g. "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.pearsonr",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._stats_py:pearsonr"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.ttest_rel",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._stats_py:ttest_rel"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ") the recommended behavior is to omit all the values   for which any of the related values are "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".  For a function with two   related array inputs, this means        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "y = func(a, b, nan_policy='omit')",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "should behave the same as        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "hasnan = np.isnan(a) | np.isnan(b)  # Union of the isnan masks.\ny = func(a[~hasnan], b[~hasnan])",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The docstring for such a function should clearly state this behavior."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan_policy='raise'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ":   Raise a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "ValueError"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan_policy='propagate'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ":   Propagate the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " value to the output.  Typically, this means just   execute the function without checking for "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nan"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", but see"
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "https://github.com/scipy/scipy/issues/7818"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "for an example where that might lead to unexpected output."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "The basic API"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There is nothing surprising here--the principle mentioned above still applies when the function has an "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter.  Suppose, for example, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " reduces a 1-d array to a scalar, and handles n-d arrays as a collection of 1-d arrays, with the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter specifying the axis along which the reduction is to be applied.  If, say      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "func([1, 3, 4])     -> 10.0\nfunc([2, -3, 8, 2]) ->  4.2\nfunc([7, 8])        ->  9.5\nfunc([])            -> -inf",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "then      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "func([[  1, nan,   3,   4],\n      [  2,  -3,   8,   2],\n      [nan,   7, nan,   8],\n      [nan, nan, nan, nan]], nan_policy='omit', axis=-1)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "must give the result      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "np.array([10.0, 4.2, 9.5, -inf])",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "nan_policy"
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " combined with an "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "axis"
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " parameter"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A function that implements the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter should gracefully handle the case where "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "all"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the values in the input array(s) are "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The basic principle described above still applies      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "func([nan, nan, nan], nan_policy='omit')",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "should behave the same as      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "func([])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In practice, when adding "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to an existing function, it is not unusual to find that the function doesn't already handle this case in a well-defined manner, and some thought and design may have to be applied to ensure that it works.  The correct behavior (whether that be to return "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", return some other value, raise an exception, or something else) will be determined on a case-by-case basis."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Edge cases"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Although we learn in grade school that \"infinity is not a number\", the floating point values "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are qualitatively different. The values "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "-inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " act much more like regular floating point values than "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "One can compare "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to other floating point values and it behaves   as expected, e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "3 < inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For the most part, arithmetic works \"as expected\" with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "inf + inf = inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "-2*inf = -inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1/inf = 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   etc."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Many existing functions work \"as expected\" with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ":   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.log(inf) = inf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.exp(-inf) = 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.array([1.0, -1.0, np.inf]).min() = -1.0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", etc."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "So while "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " almost always means \"something went wrong\" or \"something is missing\", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can in many cases be treated as a useful floating point value."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It is also consistent with the NumPy "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " functions to not ignore "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> np.nanmax([1, 2, 3, np.inf, np.nan])\ninf\n>>> np.nansum([1, 2, 3, np.inf, np.nan])\ninf\n>>> np.nanmean([8, -np.inf, 9, 1, np.nan])\n-inf",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Why doesn't "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "nan_policy"
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " also apply to "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "inf"
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "?"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In the past (and possibly currently), some "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "stats"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " functions handled "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan_policy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " by using a masked array to mask the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nan"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " values, and then computing the result using the functions in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "mstats"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " subpackage. The problem with this approach is that the masked array code might convert "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "inf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to a masked value, which we don't want to do (see above).  It also means that, if care is not taken, the return value will be a masked array, which will likely be a surprise to the user if they passed in regular arrays."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "rubric",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Footnotes"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "1",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "If an element of the output depends only on the corresponding          element of the input (e.g. "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.sin",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy:sin"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "scipy.special.gamma",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "),          then there is no need for a "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "nan_policy"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " parameter."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "How "
        },
        {
          "__type": "Emphasis",
          "__tag": 4047,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "not"
            }
          ]
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " to implement "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "nan_policy"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}