{
  "__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:contributor:adding_new",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "While adding code to SciPy is in most cases quite straight forward, there are a few places where that is not the case. This document contains detailed information on some specific situations where it may not be clear from the outset what is involved in the task."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For hundreds of years statisticians, mathematicians and scientists have needed to understand, analyze and model data. This has led to a plethora of statistics distributions, many of which are related to others. Modeling of new types of data continues to give rise to new distributions, as does theoretical considerations being applied to new disciplines. SciPy models about a dozen discrete distributions "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "discrete-random-variables",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:discrete"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and 100 continuous distributions "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "continuous-random-variables",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:continuous"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To add a new distribution, a good reference is needed. Scipy typically uses "
            },
            {
              "__type": "CitationReference",
              "__tag": 4063,
              "label": "JKB"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " as its gold standard, with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "WikipediaDistributions_",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " articles often providing some extra details and/or graphical plots."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are a few steps to be done to add a continuous distribution to SciPy. (Adding a discrete distribution is similar). We'll use the fictitious \"Squirrel\" distribution in the instructions below."
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "See if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Squirrel"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has already been implemented--that saves a lot    of effort!"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "It may have been implemented with a different name."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "It may have been implemented with a different parameterization      (shape parameters)."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "It may be a specialization of a more general family of distributions."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "It is very common for multiple disciplines to discover/rediscover a    distribution (or a specialization or different parameterization).    There are a few existing SciPy distributions which are specializations    of other distributions.  E.g. The "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "scipy.stats.arcsine",
                      "domain": null,
                      "role": "class",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " distribution    is a specialization of the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "scipy.stats.beta",
                      "domain": null,
                      "role": "class",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " distribution.    These duplications exist for (very!) historical and widespread usage reasons.    At this time, adding new specializations/reparametrizations of existing    distributions to SciPy is not supported,  mainly due to the increase in user    confusion resulting from such additions."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Create a "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "SciPy Issue on GitHub"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/issues",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",    listing the distribution, references and reasons for its inclusion."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Find an already existing distribution similar to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Squirrel"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".    Use its code as a template for "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Squirrel"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Read the docstring for class "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rv_continuous"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "scipy/stats/_distn_infrastructure.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/_distn_infrastructure.py#L1378",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Write the new code for class "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and insert it into    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "scipy/stats/_continuous_distns.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/_continuous_distns.py",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",    which is in (mostly) alphabetical order by distribution name."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Does the distribution have infinite support? If not, left and/or right    endpoints "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "a"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "b"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " need to be specified in the call to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen(name='squirrel', a=?, b=?)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If the support depends upon the shape parameters,    "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen._get_support()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " needs to be implemented."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The default inherited "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "_argcheck()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " implementation checks that the shape parameters    are positive.  Create a more appropriate implementation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen.ppf()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is expensive to compute relative to    "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen.pdf()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", consider setting the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "momtype"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the call    to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen.rvs()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is expensive to compute, consider implementing a    specific "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "squirrel_gen._rvs()"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add the name to the listing in the docstring of    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "scipy/stats/__init__.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/__init__.py",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add the name and a good set of example shape parameters to the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "distcont"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    list in    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "scipy/stats/_distr_params.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/_distr_params.py#L5",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".    These shape parameters are used both for testing and automatic documentation generation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add the name and an _invalid_ set of example shape parameters to the    list in "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "invdistcont"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", also in    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "_distr_params.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/_distr_params.py",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".    These shape parameters are also used for testing."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "TestSquirrel"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " class and any specific tests to    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "scipy/stats/tests/test_distributions.py"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/scipy/stats/tests/test_distributions.py",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Run and pass(!) the tests."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add a tutorial "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "doc/source/tutorial/stats/continuous_squirrel.rst"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Add it to the listing of continuous distributions in    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "doc/source/tutorial/stats/continuous.rst"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/doc/source/tutorial/stats/continuous.rst",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Update the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "number of continuous distributions"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the example code in    "
                    },
                    {
                      "__type": "Link",
                      "__tag": 4049,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "doc/source/tutorial/stats.rst"
                        }
                      ],
                      "url": "https://github.com/scipy/scipy/blob/main/doc/source/tutorial/stats.rst",
                      "title": ""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Build the documentation successfully."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Submit a PR."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Citation",
          "__tag": 4064,
          "label": "JKB",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Johnson, Kotz, and Balakrishnan, \"Continuous Univariate Distributions, Volume 1\", Second Edition, John Wiley and Sons, p. 173 (1994)."
                }
              ]
            }
          ]
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "WikipediaDistributions"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Adding New Methods, Functions, and Classes"
        }
      ],
      "level": 0,
      "target": "adding-new"
    }
  ],
  "local_refs": []
}