internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: gammapy/gammapy

Issue:
Incorrect return type for `Geom.energy_mask`
`Geom.energy_mask` returns a `Map` wit the same geometry as the parent `Geom`. This is incorrect in the currentl documentation which states the return type is `np.array`: https://github.com/gammapy/gammapy/blob/e5aecb334e7aebe304affd96b545a636019f7626/gammapy/maps/geom.py#L628





Discussion:

Resolving patch:
diff --git a/gammapy/maps/geom.py b/gammapy/maps/geom.py
--- a/gammapy/maps/geom.py
+++ b/gammapy/maps/geom.py
@@ -625,8 +625,9 @@ def energy_mask(self, energy_min=None, energy_max=None, round_to_edge=False):
 
         Returns
         -------
-        mask : `~numpy.ndarray`
-            Energy mask.
+        mask : `~gammapy.maps.Map`
+            Map containing the energy mask. The geometry of the map
+            is the same as the geometry of the instance which called this method.
         """
         from . import Map
 


Test patch:
Repository: gammapy/gammapy

Issue:
Defaults for `methods` in signature of `SafeMaskMaker.__init__` is confusing
```
    def __init__(
        self,
        methods=("aeff-default",),
        aeff_percent=10,
        bias_percent=10,
        position=None,
        fixed_offset=None,
        offset_max="3 deg",
        irfs="DL4",
    ):
```

In the signature of the `SafeMaskMaker`, the methods arguments is defaults to `("aeff-default",)` which is confusing because the coma is necessary for the code to work. If one don't put the coma while using a tuple, in the code latter, the instruction `set(methods)` will give back `{'-', 'a', 'd', 'e', 'f', 'l', 't', 'u'}`. To make it less confusing I think it would be good change the tuple to a list, for which `set(["aeff-default"])` give back `{'aeff-default'}`.


Discussion:

Resolving patch:
diff --git a/gammapy/makers/safe.py b/gammapy/makers/safe.py
--- a/gammapy/makers/safe.py
+++ b/gammapy/makers/safe.py
@@ -62,7 +62,7 @@ class SafeMaskMaker(Maker):
 
     def __init__(
         self,
-        methods=("aeff-default",),
+        methods=["aeff-default"],
         aeff_percent=10,
         bias_percent=10,
         position=None,


Test patch:
Repository: gammapy/gammapy

Issue:
`FluxPoints.recompute_ul` fails for multidimensional flux points
**Gammapy version**
present dev, 1.2


**Bug description**
`FluxPoints.recompute_ul` fails for multidimensional flux points

**To Reproduce**

On the light curve extracted in the flare notebook (`lc_1d`), run `lc_1d.recompute_ul(3)`

This lead to the error:

```
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[37], line 1
----> 1 lc_1d.recompute_ul(3)

File ~/anaconda3/envs/gammapy-1.2/lib/python3.10/site-packages/gammapy/estimators/points/core.py:814, in FluxPoints.recompute_ul(self, n_sigma_ul, **kwargs)
    811 shape_axes = self.stat_scan.geom._shape[slice(3, None)]
    812 for idx in np.ndindex(shape_axes):
    813     stat_scan = np.abs(
--> 814         self.stat_scan.data[idx].squeeze() - self.stat.data[idx].squeeze()
    815     )
    816     flux_points.norm_ul.data[idx] = stat_profile_ul_scipy(
    817         value_scan, stat_scan, delta_ts=delta_ts, **kwargs
    818     )
    819 flux_points.meta["n_sigma_ul"] = n_sigma_ul

IndexError: index 1 is out of bounds for axis 1 with size 1
```




Discussion:

Resolving patch:
diff --git a/gammapy/estimators/points/core.py b/gammapy/estimators/points/core.py
--- a/gammapy/estimators/points/core.py
+++ b/gammapy/estimators/points/core.py
@@ -806,7 +806,7 @@ def recompute_ul(self, n_sigma_ul=2, **kwargs):
         flux_points = deepcopy(self)
 
         value_scan = self.stat_scan.geom.axes["norm"].center
-        shape_axes = self.stat_scan.geom._shape[slice(3, None)]
+        shape_axes = self.stat_scan.geom._shape[slice(3, None)][::-1]
         for idx in np.ndindex(shape_axes):
             stat_scan = np.abs(
                 self.stat_scan.data[idx].squeeze() - self.stat.data[idx].squeeze()


Test patch:
diff --git a/gammapy/estimators/points/tests/test_lightcurve.py b/gammapy/estimators/points/tests/test_lightcurve.py
--- a/gammapy/estimators/points/tests/test_lightcurve.py
+++ b/gammapy/estimators/points/tests/test_lightcurve.py
@@ -708,17 +708,24 @@ def test_recompute_ul():
     datasets = get_spectrum_datasets()
     selection = ["all"]
     estimator = LightCurveEstimator(
-        energy_edges=[1, 3, 30] * u.TeV, selection_optional=selection, n_sigma_ul=2
+        energy_edges=[1, 3, 10, 30] * u.TeV, selection_optional=selection, n_sigma_ul=2
     )
     lightcurve = estimator.run(datasets)
+
     assert_allclose(
-        lightcurve.dnde_ul.data[0], [[[3.260703e-13]], [[1.159354e-14]]], rtol=1e-3
+        lightcurve.dnde_ul.data[0],
+        [[[3.26070325e-13]], [[3.82484628e-14]], [[4.16433528e-15]]],
+        rtol=1e-3,
     )
 
     new_lightcurve = lightcurve.recompute_ul(n_sigma_ul=4)
+
     assert_allclose(
-        new_lightcurve.dnde_ul.data[0], [[[3.758136e-13]], [[1.373942e-14]]], rtol=1e-3
+        new_lightcurve.dnde_ul.data[0],
+        [[[3.75813611e-13]], [[4.63590079e-14]], [[5.64634904e-15]]],
+        rtol=1e-3,
     )
+
     assert new_lightcurve.meta["n_sigma_ul"] == 4
 
     # test if scan is not present
Repository: gammapy/gammapy

Issue:
`plot_regions` fails when using linewidth with a  `PointSpatialModel` and extended spatial model
**Gammapy version**
gammapy v1.2

**Bug description**
When utilising `plot_regions` to plot different models, if a `PointSpatialModel` is included it somehow tries to include some of the `**kwargs` instead of only utilising `kwargs_point`. Trying to utilise `linewidth` specifically results in an error. 
This is not present when only non `PointSpatialModels` are used.

**To Reproduce**
To reproduce see the small code [here](https://gist.github.com/Astro-Kirsty/cfa975c9938043a37b6043a3ad968ee3). 
```
models.plot_regions(ax=ax, kwargs_point=dict(marker="o", fillstyle='full'),
                      edgecolor="deepskyblue", facecolor="deepskyblue", linewidth=2)
```




Discussion:

Resolving patch:
diff --git a/gammapy/visualization/utils.py b/gammapy/visualization/utils.py
--- a/gammapy/visualization/utils.py
+++ b/gammapy/visualization/utils.py
@@ -24,8 +24,8 @@
     "ec": "markeredgecolor",
     "facecolor": "markerfacecolor",
     "fc": "markerfacecolor",
-    "linewidth": "markerwidth",
-    "lw": "markerwidth",
+    "linewidth": "markeredgewidth",
+    "lw": "markeredgewidth",
 }
 
 


Test patch:
diff --git a/gammapy/modeling/models/tests/test_core.py b/gammapy/modeling/models/tests/test_core.py
--- a/gammapy/modeling/models/tests/test_core.py
+++ b/gammapy/modeling/models/tests/test_core.py
@@ -215,7 +215,7 @@ def test_plot_models(caplog):
     models = Models.read("$GAMMAPY_DATA/tests/models/gc_example_models.yaml")
 
     with mpl_plot_check():
-        models.plot_positions()
+        models.plot_regions(linewidth=2)
         models.plot_regions()
 
     assert models.wcs_geom.data_shape == models.wcs_geom.wcs.array_shape
Repository: gammapy/gammapy

Issue:
Shape of MapCoord for large non-spatial dimension
**Gammapy version 1.1**

**Bug description**
When creating a MapCoord with 2 coordinates and 3 energy bins calling the `shape` attribute results in a value error.  


**To Reproduce**
Following the example in `MapCoord.create` but using three energies instead of one.
```
from astropy.coordinates import SkyCoord
from gammapy.maps import MapCoord
lon, lat = [1, 2], [2, 3]
skycoord = SkyCoord(lon, lat, unit='deg')
energy = [1000, 3000, 5000]
c = MapCoord.create(dict(skycoord=skycoord,energy=energy))
c.shape
```
Resulting errormessage:
```
ValueError: shape mismatch: objects cannot be broadcast to a single shape.  Mismatch is between arg 0 with shape (2,) and arg 2 with shape (3,).
```


Discussion:
Thanks @katrinstreil, I think the behavior is completely correct. The coordinate arrays cannot be broadcasted to a single shape. What was the behavior you expected?
In the description of the `MapCoord` it says: `Contains coordinates for 2 spatial dimensions and an arbitrary number of additional non-spatial dimensions.` So I would expect that initialising with an arbitrary number of energies and calling `shape` is possible. 
> Contains coordinates for 2 spatial dimensions and an arbitrary number of additional non-spatial dimensions.

That's a misunderstanding: the arbitrary number of non-spatial dimensions refers to the dimension of the coordinate system. So "lon, lat" is 2d, "lon, lat, energy" is 3d etc. The number of non-spatial dimensions (energy, time, event class) can be arbitrary. For the actual coordinate arrays, broadcasting rules must apply. Probably we should improve the docs in this regard.
@katrinstreil Note that if you rather have `energy = np.array([1000, 3000, 5000]).reshape(-1,1)` (ie, correctly broadcasted), then your example works.

We should probably add some examples in the docstring as well...
@adonath can it be made to break on `init`?  That makes it easier to understand, otherwise, it seems that the `MapCoord` is created but something is funny with its shape

Resolving patch:
diff --git a/gammapy/maps/coord.py b/gammapy/maps/coord.py
--- a/gammapy/maps/coord.py
+++ b/gammapy/maps/coord.py
@@ -28,9 +28,10 @@ class MapCoord:
     """Represents a sequence of n-dimensional map coordinates.
 
     Contains coordinates for 2 spatial dimensions and an arbitrary
-    number of additional non-spatial dimensions.
+    number of additional non-spatial dimensions. Ensure correct broadcasting of the array
+    to allow for this.
 
-    For further information see :ref:`mapcoord`.
+    For further information and examples see :ref:`mapcoord`.
 
     Parameters
     ----------


Test patch:
Repository: gammapy/gammapy

Issue:
FluxPoints.write() is ignoring overwrite when file extension is not FITS
**Gammapy version**

1.2

**Bug description**

When writing a `FluxPoints` table (_.ecsv_) to file it is not possible to overwrite it.

**Expected behavior**

The `overwrite` argument should be taken into account.

**To Reproduce**

From any analysis get a `FluxPoints` instance (in my case it was from obtained from `LightCurveEstimator.run()`)
and call the `write()` method with `overwrite=True`.

You will get the following error,

`OSError: File xxxxxx.ecsv already exists. If you mean to replace it then use the argument "overwrite=True".`

**Other information**

The bug is here: https://github.com/gammapy/gammapy/blob/2475a006e02ac1497eccc362de61e68a5f7a10eb/gammapy/estimators/points/core.py#L270

It should be sufficient to pass the `overwrite` argument to `table.write()`, because the default (inherited from `astropy.table.Table.write()`) is `False`.


Discussion:

Resolving patch:
diff --git a/gammapy/estimators/points/core.py b/gammapy/estimators/points/core.py
--- a/gammapy/estimators/points/core.py
+++ b/gammapy/estimators/points/core.py
@@ -267,7 +267,7 @@ def write(
         table = self.to_table(sed_type=sed_type, format=format)
 
         if ".fits" not in filename.suffixes:
-            table.write(filename)
+            table.write(filename, overwrite=overwrite)
             return
 
         primary_hdu = fits.PrimaryHDU()


Test patch:
diff --git a/gammapy/estimators/points/tests/test_core.py b/gammapy/estimators/points/tests/test_core.py
--- a/gammapy/estimators/points/tests/test_core.py
+++ b/gammapy/estimators/points/tests/test_core.py
@@ -211,12 +211,14 @@ def test_write_fits(self, tmp_path, flux_points):
         assert str(flux_points) == str(actual)
 
     def test_write_ecsv(self, tmp_path, flux_points):
+        filename = tmp_path / "flux_points.ecsv"
+        filename.touch()
         flux_points.write(
-            tmp_path / "flux_points.ecsv",
+            filename,
             sed_type=flux_points.sed_type_init,
             overwrite=True,
         )
-        actual = FluxPoints.read(tmp_path / "flux_points.ecsv")
+        actual = FluxPoints.read(filename)
         actual._data.pop("is_ul", None)
         flux_points._data.pop("is_ul", None)
         assert str(flux_points) == str(actual)
Repository: gammapy/gammapy

Issue:
Writing `EventList` with `Observation.write` set `MJDREFI` and `MJDREFF` to 0
When one write an `EventList` with `Observation.write`, `MJDREFI` and `MJDREFF` are set to 0 in the header of the `EventList`. 
This obviously jeopardize the time of the written `EventList`.

This behaviour originates from updating the header of the `EventList` with pointing information without passing the reference time: 
https://github.com/gammapy/gammapy/blob/2475a006e02ac1497eccc362de61e68a5f7a10eb/gammapy/data/observations.py#L581
Therefore, https://github.com/gammapy/gammapy/blob/2475a006e02ac1497eccc362de61e68a5f7a10eb/gammapy/utils/time.py#L25 is used.


Discussion:

Resolving patch:
diff --git a/gammapy/data/observations.py b/gammapy/data/observations.py
--- a/gammapy/data/observations.py
+++ b/gammapy/data/observations.py
@@ -578,7 +578,9 @@ def write(
         events = self.events
         if events is not None:
             events_hdu = events.to_table_hdu(format=format)
-            events_hdu.header.update(self.pointing.to_fits_header())
+            events_hdu.header.update(
+                self.pointing.to_fits_header(time_ref=events.time_ref)
+            )
             hdul.append(events_hdu)
 
         gti = self.gti


Test patch:
diff --git a/gammapy/data/tests/test_observations.py b/gammapy/data/tests/test_observations.py
--- a/gammapy/data/tests/test_observations.py
+++ b/gammapy/data/tests/test_observations.py
@@ -378,6 +378,8 @@ def test_observation_write(tmp_path):
     obs = Observation.read(
         "$GAMMAPY_DATA/hess-dl3-dr1/data/hess_dl3_dr1_obs_id_023523.fits.gz"
     )
+    mjdreff = obs.events.table.meta["MJDREFF"]
+    mjdrefi = obs.events.table.meta["MJDREFI"]
     path = tmp_path / "obs.fits.gz"
 
     obs.meta.creation.origin = "test"
@@ -393,6 +395,9 @@ def test_observation_write(tmp_path):
     assert obs_read.obs_id == 23523
     assert_allclose(obs_read.observatory_earth_location.lat.deg, -23.271778)
 
+    assert_allclose(obs_read.events.table.meta["MJDREFF"], mjdreff)
+    assert_allclose(obs_read.events.table.meta["MJDREFI"], mjdrefi)
+
     # unsupported format
     with pytest.raises(ValueError):
         obs.write(tmp_path / "foo.fits.gz", format="cool-new-format")
Repository: Zeroto521/my-data-toolkit

Issue:
BUG: feature_union can't concat different dataframe well
https://github.com/Zeroto521/my-data-toolkit/blob/8b6ec3ce2658626f265bf5e1bab5a7c0897a0787/dtoolkit/transformer.py#L55-L56

When we use transformers to handle data frames, some rows would be deleted.
So use the feature union transformer would cause the following problem.

```python
0   1.0  0.0  0.0  1.0  0.0  ...    0.070607     0.0   1.0    1.0     1.0
1   0.0  1.0  0.0  1.0  0.0  ...    0.000000     0.0   1.0    1.0     1.0
2   0.0  0.0  1.0  0.0  1.0  ...    0.853865     1.0   1.0    1.0     1.0
3   0.0  0.0  1.0  0.0  1.0  ...    0.279593     0.0   0.0    1.0     0.0
4   0.0  0.0  1.0  1.0  0.0  ...    1.000000     0.0   1.0    1.0     0.0
5   1.0  0.0  0.0  0.0  1.0  ...    0.566105     0.0   0.0    1.0     0.0
6   0.0  1.0  0.0  1.0  0.0  ...    0.007911     0.0   1.0    0.0     1.0
7   0.0  1.0  0.0  1.0  0.0  ...    0.220168     0.0   1.0    0.0     1.0
8   0.0  1.0  0.0  1.0  0.0  ...    0.242736     0.0   1.0    0.0     1.0
9   1.0  0.0  0.0  1.0  0.0  ...    0.491557     0.0   1.0    0.0     1.0
10  1.0  0.0  0.0  0.0  1.0  ...         NaN     NaN   NaN    NaN     NaN
11  NaN  NaN  NaN  NaN  NaN  ...    0.184352     0.0   1.0    0.0     1.0
```

We could see, row index 10 and 11 data have NaN.

To fix this, there should add a parameter to ignore the index then concat data.


Discussion:

Resolving patch:
diff --git a/dtoolkit/transformer.py b/dtoolkit/transformer.py
--- a/dtoolkit/transformer.py
+++ b/dtoolkit/transformer.py
@@ -13,6 +13,7 @@
 from ._checking import check_dataframe_type
 from ._checking import istype
 from ._typing import PandasTypeList
+from .accessor import ColumnAccessor  # noqa
 from .accessor import FilterInAccessor  # noqa
 
 
@@ -53,6 +54,7 @@ def _hstack(self, Xs):
             return sparse.hstack(Xs).tocsr()
 
         if all(istype(i, PandasTypeList) for i in Xs):
+            Xs = (i.reset_index(drop=True) for i in Xs)
             return pd.concat(Xs, axis=1)
 
         return np.hstack(Xs)


Test patch:
diff --git a/dtoolkit/tests/test_transformer.py b/dtoolkit/tests/test_transformer.py
--- a/dtoolkit/tests/test_transformer.py
+++ b/dtoolkit/tests/test_transformer.py
@@ -281,3 +281,27 @@ def test_union_pipeline(pipeline):
     res = pipeline.fit_transform(df_mixed)
 
     assert isinstance(res, pd.DataFrame)
+
+
+def test_issue_87():
+    tf = make_union(
+        make_pipeline(
+            GetTF(["a"]),
+            FilterInTF({"a": [0]}),
+        ),
+        make_pipeline(
+            GetTF(["b"]),
+            FilterInTF({"b": [1]}),
+        ),
+    )
+
+    res = tf.fit_transform(
+        pd.DataFrame(
+            {
+                "a": [0, 1, 0],
+                "b": [1, 1, 0],
+            },
+        ),
+    )
+
+    assert res.notnull().all(axis=None)
Repository: Zeroto521/my-data-toolkit

Issue:
DEV: rename master to main
https://github.com/github/renaming


Discussion:

Resolving patch:
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -107,7 +107,7 @@
 
     This page was generated from `{{ docname }}`__.
 
-    __ https://github.com/zeroto521/my-data-toolkit/blob/master/doc/source/{{ docname }}
+    __ https://github.com/zeroto521/my-data-toolkit/blob/main/doc/source/{{ docname }}
 """
 
 
@@ -187,6 +187,6 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None:
 
     base_link = f"{github_url}/blob/" + "{branch}" + f"/dtoolkit/{fn}{linespec}"
     if "post" in version:
-        return base_link.format(branch="master")
+        return base_link.format(branch="main")
 
     return base_link.format(branch=f"v{version}")


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -2,9 +2,9 @@ name: tests
 
 on:
   push:
-    branches: [master]
+    branches: [main]
   pull_request:
-    branches: [master]
+    branches: [main]
 
 jobs:
   tests:
Repository: Zeroto521/my-data-toolkit

Issue:
BUG: feature_union can't concat different dataframe well
https://github.com/Zeroto521/my-data-toolkit/blob/8b6ec3ce2658626f265bf5e1bab5a7c0897a0787/dtoolkit/transformer.py#L55-L56

When we use transformers to handle data frames, some rows would be deleted.
So use the feature union transformer would cause the following problem.

```python
0   1.0  0.0  0.0  1.0  0.0  ...    0.070607     0.0   1.0    1.0     1.0
1   0.0  1.0  0.0  1.0  0.0  ...    0.000000     0.0   1.0    1.0     1.0
2   0.0  0.0  1.0  0.0  1.0  ...    0.853865     1.0   1.0    1.0     1.0
3   0.0  0.0  1.0  0.0  1.0  ...    0.279593     0.0   0.0    1.0     0.0
4   0.0  0.0  1.0  1.0  0.0  ...    1.000000     0.0   1.0    1.0     0.0
5   1.0  0.0  0.0  0.0  1.0  ...    0.566105     0.0   0.0    1.0     0.0
6   0.0  1.0  0.0  1.0  0.0  ...    0.007911     0.0   1.0    0.0     1.0
7   0.0  1.0  0.0  1.0  0.0  ...    0.220168     0.0   1.0    0.0     1.0
8   0.0  1.0  0.0  1.0  0.0  ...    0.242736     0.0   1.0    0.0     1.0
9   1.0  0.0  0.0  1.0  0.0  ...    0.491557     0.0   1.0    0.0     1.0
10  1.0  0.0  0.0  0.0  1.0  ...         NaN     NaN   NaN    NaN     NaN
11  NaN  NaN  NaN  NaN  NaN  ...    0.184352     0.0   1.0    0.0     1.0
```

We could see, row index 10 and 11 data have NaN.

To fix this, there should add a parameter to ignore the index then concat data.


Discussion:

Resolving patch:
diff --git a/dtoolkit/transformer/sklearn.py b/dtoolkit/transformer/sklearn.py
--- a/dtoolkit/transformer/sklearn.py
+++ b/dtoolkit/transformer/sklearn.py
@@ -52,8 +52,8 @@ class FeatureUnion(SKFeatureUnion, Transformer):
 
     def _hstack(self, Xs):
         if all(isinstance(i, (pd.Series, pd.DataFrame)) for i in Xs):
-            Xs = (i.reset_index(drop=True) for i in Xs)
-            return pd.concat(Xs, axis=1)
+            # merge all into one DataFrame and the index would use the common part
+            return pd.concat(Xs, axis=1, join="inner")
 
         return super()._hstack(Xs)
 


Test patch:
diff --git a/test/transformer/test_pipeline.py b/test/transformer/test_pipeline.py
--- a/test/transformer/test_pipeline.py
+++ b/test/transformer/test_pipeline.py
@@ -147,4 +147,6 @@ def test_issue_87():
         ),
     )
 
+    assert isinstance(res, pd.DataFrame)
+    assert len(res) == 1
     assert res.notnull().all(axis=None)
Repository: Zeroto521/my-data-toolkit

Issue:
TYP: specific `None` type
<!--
Thanks for contributing a pull request!

Please follow these standard acronyms to start the commit message:

- ENH: enhancement
- BUG: bug fix
- DOC: documentation
- TYP: type annotations
- TST: addition or modification of tests
- MAINT: maintenance commit (refactoring, typos, etc.)
- BLD: change related to building
- REL: related to releasing
- API: an (incompatible) API change
- DEP: deprecate something, or remove a deprecated object
- DEV: development tool or utility
- REV: revert an earlier commit
- PERF: performance improvement
- BOT: always commit via a bot
- CI: related to CI or CD
- CLN: Code cleanup
-->

- [ ] closes #xxxx
- [x] whatsnew entry

`paramerter: TheType = None` means `parameter` is `Optional[TheType]`.
`parameter: None` means `None` has any specifal function.


Discussion:

Resolving patch:
diff --git a/dtoolkit/accessor/series.py b/dtoolkit/accessor/series.py
--- a/dtoolkit/accessor/series.py
+++ b/dtoolkit/accessor/series.py
@@ -382,7 +382,7 @@ def lens(s: pd.Series, number: int = 1, other: int = None) -> pd.Series:
 
     Parameters
     ----------
-    number : int or None, default '1'
+    number : int, default 1
         The default length of `number` type.
     other : int or None, default None
         The default length of `other` type.


Test patch: