internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: scikit-hep/pyhf

Issue:
Class returned by pyhf.Workspace.combine
# Question

Not a bug so I'm opening this as a question: The `pyhf.Workspace.combine` classmethod returns a `Workspace` explicitly instead of `cls`.

https://github.com/scikit-hep/pyhf/blob/e260626689f46414be185d834499cc65dce5a4b0/src/pyhf/workspace.py#L678

To work better with classes that want to inherit from `pyhf.Workspace`, I think it would be better to return the class as

```python
return cls(newspec) 
```

# Relevant Issues and Pull Requests

none I'm aware of



Discussion:
Hah.. good point. I feel like a hypocrite for writing it this way when we had to fix this with iminuit :)

Resolving patch:
diff --git a/src/pyhf/workspace.py b/src/pyhf/workspace.py
--- a/src/pyhf/workspace.py
+++ b/src/pyhf/workspace.py
@@ -675,4 +675,4 @@ def combine(cls, left, right, join='none'):
             'observations': new_observations,
             'version': new_version,
         }
-        return Workspace(newspec)
+        return cls(newspec)


Test patch:
diff --git a/tests/test_workspace.py b/tests/test_workspace.py
--- a/tests/test_workspace.py
+++ b/tests/test_workspace.py
@@ -717,3 +717,32 @@ def test_workspace_equality(workspace_factory):
     assert ws == ws
     assert ws == ws_other
     assert ws != 'not a workspace'
+
+
+def test_workspace_inheritance(workspace_factory):
+    ws = workspace_factory()
+    new_ws = ws.rename(
+        channels={'channel1': 'channel3', 'channel2': 'channel4'},
+        samples={
+            'background1': 'background3',
+            'background2': 'background4',
+            'signal': 'signal2',
+        },
+        modifiers={
+            'syst1': 'syst4',
+            'bkg1Shape': 'bkg3Shape',
+            'bkg2Shape': 'bkg4Shape',
+        },
+        measurements={
+            'GaussExample': 'OtherGaussExample',
+            'GammaExample': 'OtherGammaExample',
+            'ConstExample': 'OtherConstExample',
+            'LogNormExample': 'OtherLogNormExample',
+        },
+    )
+
+    class FooWorkspace(pyhf.Workspace):
+        pass
+
+    combined = FooWorkspace.combine(ws, new_ws)
+    assert isinstance(combined, FooWorkspace)
Repository: scikit-hep/pyhf

Issue:
Missing tensorlib conversion for Model.main_model.expected_data
# Description

This is the same issue as #1027, but for `Model.main_model.expected_data` instead. I missed it earlier due to the workaround I had been using for #1027. That function is particularly interesting for the `return_by_sample` behavior introduced by #731.

```python
import pyhf

model = pyhf.simplemodels.hepdata_like(
    signal_data=[12.0, 11.0], bkg_data=[50.0, 52.0], bkg_uncerts=[3.0, 7.0]
)

model.main_model.expected_data(model.config.suggested_init())
```

results in

```
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    model.main_model.expected_data(model.config.suggested_init())
  File "[...]pyhf/src/pyhf/pdf.py", line 517, in expected_data
    deltas, factors = self._modifications(pars)
  File "[...]pyhf/src/pyhf/pdf.py", line 483, in _modifications
    [self.modifiers_appliers[k].apply(pars) for k in self._factor_mods],
  File "[...]pyhf/src/pyhf/pdf.py", line 483, in <listcomp>
    [self.modifiers_appliers[k].apply(pars) for k in self._factor_mods],
  File "[...]pyhf/src/pyhf/modifiers/shapesys.py", line 169, in apply
    shapefactors = tensorlib.gather(flat_pars, self.access_field)
  File "[...]pyhf/src/pyhf/tensor/numpy_backend.py", line 136, in gather
    return tensor[indices]
TypeError: only integer scalar arrays can be converted to a scalar index
```

# Expected Behavior

no crash, but successful return of expected data

# Actual Behavior

crash with `TypeError: only integer scalar arrays can be converted to a scalar index`

# Steps to Reproduce

`pyhf` master @ 236fbaa, see above

# Checklist

- [ ] Run `git fetch` to get the most up to date version of `master`
- [ ] Searched through existing Issues to confirm this is not a duplicate issue
- [ ] Filled out the Description, Expected Behavior, Actual Behavior, and Steps to Reproduce sections above or have edited/removed them in a way that fully describes the issue



Discussion:

Resolving patch:
diff --git a/src/pyhf/pdf.py b/src/pyhf/pdf.py
--- a/src/pyhf/pdf.py
+++ b/src/pyhf/pdf.py
@@ -514,6 +514,7 @@ def expected_data(self, pars, return_by_sample=False):
 
         """
         tensorlib, _ = get_backend()
+        pars = tensorlib.astensor(pars)
         deltas, factors = self._modifications(pars)
 
         allsum = tensorlib.concatenate(deltas + [self.nominal_rates])


Test patch:
diff --git a/tests/test_pdf.py b/tests/test_pdf.py
--- a/tests/test_pdf.py
+++ b/tests/test_pdf.py
@@ -139,6 +139,9 @@ def test_pdf_basicapi_tests(backend):
     assert tensorlib.tolist(pdf.expected_auxdata(pars)) == pytest.approx(
         [51.020408630], 1e-08
     )
+    assert tensorlib.tolist(pdf.main_model.expected_data(pars)) == pytest.approx(
+        [60.0], 1e-08
+    )
 
     pdf = pyhf.simplemodels.hepdata_like(
         source['bindata']['sig'],
Repository: scikit-hep/pyhf

Issue:
Migrate from bumpversion to bump2version
# Description

@dguest has brought to my attention that [`bumpversion` is no longer maintained](https://github.com/peritus/bumpversion) (as of apparently November 2019). Given this we should probably take the project's advice

> 🎬 If you want to start using `bumpversion`, you're best advised to install one of the maintained forks, e.g. ➡ @ c4urself's [`bump2version`](https://github.com/c4urself/bump2version/#installation).

given that it seems that [transferring ownership and maintainers is taking a very long time/might not happen](https://github.com/c4urself/bump2version/issues/86).


Discussion:
is it just as easy as switching to `bump2version`?
> is it just as easy as switching to `bump2version`?

I think so as `bump2version` is just a direct fork and uses `.bumpversion.cfg`. I just made this Issue as more of a reminder to myself.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -65,7 +65,7 @@
         extras_require['docs']
         + extras_require['lint']
         + extras_require['test']
-        + ['nbdime', 'bumpversion', 'ipython', 'pre-commit', 'check-manifest', 'twine']
+        + ['nbdime', 'bump2version', 'ipython', 'pre-commit', 'check-manifest', 'twine']
     )
 )
 extras_require['complete'] = sorted(set(sum(extras_require.values(), [])))


Test patch:
Repository: scikit-hep/pyhf

Issue:
Write JOSS Submission
# Description

Given conversations with @labarba at SciPy 2019 it seems that pyhf would be a good candidate for a [JOSS paper](https://joss.theoj.org/). Given @cranmer's good experience with this for carl [![DOI](http://joss.theoj.org/papers/10.21105/joss.00011/status.svg)](https://doi.org/10.21105/joss.00011) it seems if we clean up and finish a few of the docstrings then we would be in good shape to submit for a review (once we finish up the other publication process we have ongoing).

The [carl paper submission review](https://github.com/openjournals/joss-reviews/issues/11) might be a good premeptive checklist for this.


Discussion:
Also see things that we did for root_numpy here (https://github.com/scikit-hep/root_numpy/issues?q=is%3Aissue+joss+is%3Aclosed+label%3AJOSS) which was under scikit-hep at the time.
Today in the SciPy 2020 Maintainers Track discussion I asked

> The pyOpenSci website mentions that "Any package that passes the pyOpenSci review and is within scope for JOSS can be fast-tracked through the JOSS review process." Would you recommend that people attempt to go through pyOpenSci review before submitting to JOSS to make it easier for the JOSS reviewers?

 @kyleniemeyer (who was presenting on behalf of JOSS) thought this was probably a good idea. So maybe we should just do the work once and a bit extra to get a [PyOpenSci](https://www.pyopensci.org/) review and then submit to JOSS.
FWIW, I think that trying to get something done with pyOpenSci is going to take too long, and we should just write up a JOSS paper and get it out. I'll take point on this and try to get something going with JOSS this weekend.
Sounds like a good idea. pyhf is in very good shape for a JOSS paper


Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -141,6 +141,7 @@ def setup(app):
 # This patterns also effect to html_static_path and html_extra_path
 exclude_patterns = [
     '_build',
+    'JOSS',
     '**.ipynb_checkpoints',
     'examples/experiments/edwardpyhf.ipynb',
     'examples/notebooks/ImpactPlot.ipynb',


Test patch:
Repository: scikit-hep/pyhf

Issue:
Top-Level Python API methods don't have docstrings rendered in docs
# Description

The top level Python API methods pages on the docs website doesn't contain any of the rendered docstrings. For example, the `pyhf.set_backend()` API has examples (and it rather important for new users)

https://github.com/scikit-hep/pyhf/blob/e55eea408d7c28e3109338de96252119ac63f87a/src/pyhf/__init__.py#L42-L52

but the docs website doesn't show any of this

![not_rendered](https://user-images.githubusercontent.com/5142394/88368070-def79000-cd52-11ea-9f0e-5acbb4d45c6b.png)


# Expected Behavior

Have the docstrings be rendered in the docs 

# Actual Behavior

c.f. above

# Steps to Reproduce

Build the docs

# Checklist

- [x] Run `git fetch` to get the most up to date version of `master`
- [x] Searched through existing Issues to confirm this is not a duplicate issue
- [x] Filled out the Description, Expected Behavior, Actual Behavior, and Steps to Reproduce sections above or have edited/removed them in a way that fully describes the issue



Discussion:
This is broken due to the fact that we put a decorator on it. We just need to use `functools.wraps` and that should fix this.

Resolving patch:
diff --git a/src/pyhf/events.py b/src/pyhf/events.py
--- a/src/pyhf/events.py
+++ b/src/pyhf/events.py
@@ -1,4 +1,5 @@
 import weakref
+from functools import wraps
 
 __events = {}
 __disabled_events = set([])
@@ -71,6 +72,7 @@ def register(event):
     # >>>
 
     def _register(func):
+        @wraps(func)
         def register_wrapper(*args, **kwargs):
             trigger("{0:s}::before".format(event))()
             result = func(*args, **kwargs)


Test patch:
Repository: scikit-hep/pyhf

Issue:
Remove use of NumPy from JAX backend
`jax.numpy` now supports `tolist` so this

https://github.com/scikit-hep/pyhf/blob/0ed1b518bf0ea137b7d676dac52575a8473950de/src/pyhf/tensor/jax_backend.py#L180-L182

 could instead be

```suggestion
            return jnp.asarray(tensor_in).tolist()
```

but this should probably be left to another follow up PR as this is a style PR where no real code is supposed to change.

_Originally posted by @matthewfeickert in https://github.com/scikit-hep/pyhf/pull/1135#discussion_r508719046_


Discussion:

Resolving patch:
diff --git a/src/pyhf/tensor/jax_backend.py b/src/pyhf/tensor/jax_backend.py
--- a/src/pyhf/tensor/jax_backend.py
+++ b/src/pyhf/tensor/jax_backend.py
@@ -179,8 +179,8 @@ def conditional(self, predicate, true_callable, false_callable):
 
     def tolist(self, tensor_in):
         try:
-            return np.asarray(tensor_in).tolist()
-        except AttributeError:
+            return jnp.asarray(tensor_in).tolist()
+        except TypeError:
             if isinstance(tensor_in, list):
                 return tensor_in
             raise


Test patch:
Repository: scikit-hep/pyhf

Issue:
Add axis labels to pyhf.contrib.viz.brazil.plot_results
# Description

We know that the axis labels for [`pyhf.contrib.viz.brazil.plot_results`](https://github.com/scikit-hep/pyhf/blob/28fdfe95a3a4846ba70a9a338b3f72a94eac1322/src/pyhf/contrib/viz/brazil.py#L5) are always going to be the same, so we should just add them on there as

```python
ax.set_xlabel(r"$\mu$")
ax.set_ylabel(r"$\mathrm{CL}_{s}$")
```


Discussion:

Resolving patch:
diff --git a/src/pyhf/contrib/viz/brazil.py b/src/pyhf/contrib/viz/brazil.py
--- a/src/pyhf/contrib/viz/brazil.py
+++ b/src/pyhf/contrib/viz/brazil.py
@@ -3,7 +3,37 @@
 
 
 def plot_results(ax, mutests, tests, test_size=0.05):
-    """Plot a series of hypothesis tests for various POI values."""
+    """
+    Plot a series of hypothesis tests for various POI values.
+
+    Example:
+
+        >>> import numpy as np
+        >>> import matplotlib.pyplot as plt
+        >>> import pyhf
+        >>> import pyhf.contrib.viz.brazil
+        >>> pyhf.set_backend("numpy")
+        >>> model = pyhf.simplemodels.hepdata_like(
+        ...     signal_data=[12.0, 11.0], bkg_data=[50.0, 52.0], bkg_uncerts=[3.0, 7.0]
+        ... )
+        >>> observations = [51, 48]
+        >>> data = observations + model.config.auxdata
+        >>> poi_vals = np.linspace(0, 5, 41)
+        >>> results = [
+        ...     pyhf.infer.hypotest(test_poi, data, model, return_expected_set=True)
+        ...     for test_poi in poi_vals
+        ... ]
+        >>> fig, ax = plt.subplots()
+        >>> pyhf.contrib.viz.brazil.plot_results(ax, poi_vals, results)
+
+    Args:
+        ax (`matplotlib.axes.Axes`): The matplotlib axis object to plot on.
+        mutests (:obj:`list` or :obj:`array`): The values of the POI where the
+          hypothesis tests were performed.
+        tests (:obj:`list` or :obj:`array`): The :math:$\\mathrm{CL}_{s}$ values
+          from the hypothesis tests.
+        test_size (:obj:`float`): The size, :math:$\alpha$, of the test.
+    """
     cls_obs = np.array([test[0] for test in tests]).flatten()
     cls_exp = [np.array([test[1][i] for test in tests]).flatten() for i in range(5)]
     ax.plot(mutests, cls_obs, c='black')
@@ -15,3 +45,6 @@ def plot_results(ax, mutests, tests, test_size=0.05):
     ax.fill_between(mutests, cls_exp[1], cls_exp[-2], facecolor='green')
     ax.plot(mutests, [test_size] * len(mutests), c='red')
     ax.set_ylim(0, 1)
+
+    ax.set_xlabel(r"$\mu$ (POI)")
+    ax.set_ylabel(r"$\mathrm{CL}_{s}$")


Test patch:
diff --git a/tests/contrib/baseline/test_brazil.png b/tests/contrib/baseline/test_brazil.png
Binary files a/tests/contrib/baseline/test_brazil.png and b/tests/contrib/baseline/test_brazil.png differ
Repository: scikit-hep/pyhf

Issue:
pyhf json2xml requires pyhf[contrib]
# Description

```
$ pip install pyhf[xmlio]
$ pyhf json2xml -h
ERROR:pyhf.contrib.utils:No module named 'requests'
Installation of the contrib extra is required to use pyhf.contrib.utils.download
Please install with: python -m pip install pyhf[contrib]

Usage: pyhf json2xml [OPTIONS] [WORKSPACE]

  Convert pyhf JSON back to XML + ROOT files.

Options:
  --output-dir PATH
  --specroot TEXT
  --dataroot TEXT
  --resultprefix TEXT
  -p, --patch TEXT
  -h, --help           Show this message and exit.
```

# Expected Behavior

Shown the help without any reference to pyhf.contrib as this does not depend on contrib.


Discussion:

Resolving patch:
diff --git a/src/pyhf/contrib/cli.py b/src/pyhf/contrib/cli.py
--- a/src/pyhf/contrib/cli.py
+++ b/src/pyhf/contrib/cli.py
@@ -3,8 +3,6 @@
 import click
 from pathlib import Path
 
-from . import utils
-
 logging.basicConfig()
 log = logging.getLogger(__name__)
 
@@ -22,6 +20,10 @@ def cli():
 
             $ python -m pip install pyhf[contrib]
     """
+    from . import utils  # Guard CLI from missing extra
+
+    # TODO: https://github.com/scikit-hep/pyhf/issues/863
+    _ = utils  # Placate pyflakes
 
 
 @cli.command()
@@ -57,6 +59,8 @@ def download(archive_url, output_directory, verbose, force, compress):
         :class:`~pyhf.exceptions.InvalidArchiveHost`: if the provided archive host name is not known to be valid
     """
     try:
+        from . import utils
+
         utils.download(archive_url, output_directory, force, compress)
 
         if verbose:


Test patch:
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -562,7 +562,7 @@ def test_missing_contrib_extra(caplog):
         if "pyhf.contrib.utils" in sys.modules:
             reload(sys.modules["pyhf.contrib.utils"])
         else:
-            import_module("pyhf.cli")
+            import_module("pyhf.contrib.utils")
 
     with caplog.at_level(logging.ERROR):
         for line in [
@@ -577,10 +577,10 @@ def test_missing_contrib_extra(caplog):
 def test_missing_contrib_download(caplog):
     with mock.patch.dict(sys.modules):
         sys.modules["requests"] = None
-        if "pyhf.cli" in sys.modules:
-            reload(sys.modules["pyhf.cli"])
+        if "pyhf.contrib.utils" in sys.modules:
+            reload(sys.modules["pyhf.contrib.utils"])
         else:
-            import_module("pyhf.cli")
+            import_module("pyhf.contrib.utils")
 
         # Force environment for runner
         for module in [
Repository: scikit-hep/pyhf

Issue:
Add pyhf.writexml and pyhf.readxml to public API docs
# Description

As first brought up in PR #1125, `pyhf.writexml` and `pyhf.readxml` are not currently documented in the public Python API docs. This should get fixed.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -49,16 +49,19 @@
     )
 )
 extras_require['docs'] = sorted(
-    {
-        'sphinx>=3.1.2',
-        'sphinxcontrib-bibtex~=1.0',
-        'sphinx-click',
-        'sphinx_rtd_theme',
-        'nbsphinx',
-        'ipywidgets',
-        'sphinx-issues',
-        'sphinx-copybutton>0.2.9',
-    }
+    set(
+        extras_require['xmlio']
+        + [
+            'sphinx>=3.1.2',
+            'sphinxcontrib-bibtex~=1.0',
+            'sphinx-click',
+            'sphinx_rtd_theme',
+            'nbsphinx',
+            'ipywidgets',
+            'sphinx-issues',
+            'sphinx-copybutton>0.2.9',
+        ]
+    )
 )
 extras_require['develop'] = sorted(
     set(


Test patch:
Repository: scikit-hep/pyhf

Issue:
Remove duplicated libraries in setup.py
# Description

In `setup.py` and `setup.cfg` there are some duplicated libraries that should be removed from `setup.py`.

https://github.com/scikit-hep/pyhf/blob/75f3cd350ed3986d16d680fbb83f312791aafd68/setup.py#L47

already exists as a core requirement in `setup.cfg`

https://github.com/scikit-hep/pyhf/blob/75f3cd350ed3986d16d680fbb83f312791aafd68/setup.cfg#L45

and so should be removed from `setup.py`.

It also isn't clear if 

https://github.com/scikit-hep/pyhf/blob/75f3cd350ed3986d16d680fbb83f312791aafd68/setup.py#L42

is still required, given that it was added back in PR #186 when we still used Coveralls for coverage.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -39,12 +39,10 @@
             'pytest-console-scripts',
             'pytest-mpl',
             'pydocstyle',
-            'coverage>=4.0',  # coveralls
             'papermill~=2.0',
             'nteract-scrapbook~=0.2',
             'jupyter',
             'graphviz',
-            'jsonpatch',
         ]
     )
 )


Test patch:
Repository: scikit-hep/pyhf

Issue:
Add commas around constrained maximal likelihood in docstring for clarity
# Description

In PR #905 the docstring for [`pyhf.infer.mle.fixed_poi_fit`](https://scikit-hep.org/pyhf/_generated/pyhf.infer.mle.fixed_poi_fit.html) was amended, but the lines

https://github.com/scikit-hep/pyhf/blob/fd7930cce36cbc3a2d0ee1828f060d7382129579/src/pyhf/infer/mle.py#L134-L135

are missing commas around the likelihood, making it difficult to read

![missing_commas](https://user-images.githubusercontent.com/5142394/102830397-d9a87b00-43ae-11eb-8acc-502370cf9353.png)

It should read

```
,:math:`L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)`, in the profile 
```

Add commas around constrained maximal likelihood in docstring for clarity
# Description

In PR #905 the docstring for [`pyhf.infer.mle.fixed_poi_fit`](https://scikit-hep.org/pyhf/_generated/pyhf.infer.mle.fixed_poi_fit.html) was amended, but the lines

https://github.com/scikit-hep/pyhf/blob/fd7930cce36cbc3a2d0ee1828f060d7382129579/src/pyhf/infer/mle.py#L134-L135

are missing commas around the likelihood, making it difficult to read

![missing_commas](https://user-images.githubusercontent.com/5142394/102830397-d9a87b00-43ae-11eb-8acc-502370cf9353.png)

It should read

```
,:math:`L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)`, in the profile 
```



Discussion:
I would like to work on this
I would like to work on this

Resolving patch:
diff --git a/src/pyhf/infer/mle.py b/src/pyhf/infer/mle.py
--- a/src/pyhf/infer/mle.py
+++ b/src/pyhf/infer/mle.py
@@ -131,8 +131,8 @@ def fixed_poi_fit(
     Run a maximum likelihood fit with the POI value fixed.
     This is done by minimizing the objective function of :func:`~pyhf.infer.mle.twice_nll`
     of the model parameters given the observed data, for a given fixed value of :math:`\mu`.
-    This is used to produce the constrained maximal likelihood for the given :math:`\mu`
-    :math:`L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)` in the profile
+    This is used to produce the constrained maximal likelihood for the given :math:`\mu`,
+    :math:`L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)`, in the profile
     likelihood ratio in Equation (7) in :xref:`arXiv:1007.1727`
 
     .. math::


Test patch:
Repository: scikit-hep/pyhf

Issue:
Change question asking queue to focus on GitHub Discussions over Stack Overflow
# Description

We currently direct users with application questions to the `pyhf` Stack Overflow tag, but should start directing them to GitHub Discussions instead.

This should be done before `v0.6.0` so that this gets propagated out to PyPI.


Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -77,7 +77,7 @@ def setup(app):
     'uproot': ('https://uproot.readthedocs.io/en/latest/', None),
 }
 
-# Github repo
+# GitHub repo
 issues_github_path = 'scikit-hep/pyhf'
 
 # Generate the API documentation when building


Test patch: