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

Issue:
BUG: broken optional dependency (pyregion)
### Bug report

**Bug summary**

`pyregion` is being used sporadically in a couple docs notebooks and is a docs-only dependency to yt. It's also quite fragile as no wheels are available and `pip` fails to build the current latest version (2.1.1) from source.
The project is targeted for retirement https://github.com/astropy/pyregion/issues/153, so we should move to `regions` when possible (maybe it's already the case).






Discussion:

Resolving patch:
diff --git a/yt/frontends/fits/misc.py b/yt/frontends/fits/misc.py
--- a/yt/frontends/fits/misc.py
+++ b/yt/frontends/fits/misc.py
@@ -135,8 +135,8 @@ def create_spectral_slabs(filename, slab_centers, slab_width, **kwargs):
 
 def ds9_region(ds, reg, obj=None, field_parameters=None):
     r"""
-    Create a data container from a ds9 region file. Requires the pyregion
-    package (https://pyregion.readthedocs.io/en/latest/) to be installed.
+    Create a data container from a ds9 region file. Requires the regions
+    package (https://astropy-regions.readthedocs.io/) to be installed.
 
     Parameters
     ----------
@@ -157,21 +157,29 @@ def ds9_region(ds, reg, obj=None, field_parameters=None):
     >>> circle_region = ds9_region(ds, "circle.reg")
     >>> print(circle_region.quantities.extrema("flux"))
     """
-    import pyregion
+    from regions import Regions
+
+    from yt.utilities.on_demand_imports import _astropy
+
+    WCS = _astropy.WCS
 
     from yt.frontends.fits.api import EventsFITSDataset
 
     if os.path.exists(reg):
-        r = pyregion.open(reg)
+        method = Regions.read
     else:
-        r = pyregion.parse(reg)
+        method = Regions.parse
+    r = method(reg, format="ds9").regions[0]
+
     reg_name = reg
     header = ds.wcs_2d.to_header()
     # The FITS header only contains WCS-related keywords
-    header["NAXIS1"] = nx = ds.domain_dimensions[ds.lon_axis]
-    header["NAXIS2"] = ny = ds.domain_dimensions[ds.lat_axis]
-    filter = r.get_filter(header=header)
-    mask = filter.mask((ny, nx)).transpose()
+    header["NAXIS1"] = ds.domain_dimensions[ds.lon_axis]
+    header["NAXIS2"] = ds.domain_dimensions[ds.lat_axis]
+
+    pixreg = r.to_pixel(WCS(header))
+    mask = pixreg.to_mask().to_image((header["NAXIS1"], header["NAXIS2"])).astype(bool)
+
     if isinstance(ds, EventsFITSDataset):
         prefix = "event_"
     else:
diff --git a/yt/utilities/on_demand_imports.py b/yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -135,6 +135,13 @@ def wcsaxes(self):
         self.log
         return wcsaxes
 
+    @safe_import
+    def WCS(self):
+        from astropy.wcs import WCS
+
+        self.log
+        return WCS
+
 
 _astropy = astropy_imports()
 


Test patch:
Repository: yt-project/yt

Issue:
BUG: CI instability (upstream change)
### Bug report

**Bug summary**

Last night's bleeding edge CI failed:
https://github.com/yt-project/yt/actions/runs/3626064400/jobs/6114722912

I'll dig into this later today


Discussion:
the error can be reproduced by installing numpy from source
```
python -m pip install git+https://github.com/numpy/numpy.git
pytest yt/visualization/tests/test_set_zlim.py::test_float_vmin_then_set_unit
```
The issue is that numpy just broke unyt

Here's a minimal reproducer
```python
import unyt as u
a = 1*u.cm
a in (None, "min")
```

It's not yet clear if this needs a fix in numpy or in unyt. I'll close this ticket once I'm ready to report upstream
reported upstream as https://github.com/numpy/numpy/issues/22744
I expect the solution will either be in unyt or numpy, but I'll keep this ticket open while it's being discussed.
fixed with the release of unyt 2.9.3
Turns out the problem still needs to be addressed in yt:
the new version of unyt now correctly lets some, previously hidden, deprecation warnings from numpy surface.
see https://github.com/yt-project/yt/actions/runs/3641878775/jobs/6148337575

Resolving patch:
diff --git a/yt/visualization/_handlers.py b/yt/visualization/_handlers.py
--- a/yt/visualization/_handlers.py
+++ b/yt/visualization/_handlers.py
@@ -285,12 +285,16 @@ def get_norm(self, data: np.ndarray, *args, **kw) -> Normalize:
         dvmin = dvmax = None
 
         finite_values_mask = np.isfinite(data)
-        if self.vmin not in (None, "min"):
+        if self.vmin is not None and not (
+            isinstance(self.vmin, str) and self.vmin == "min"
+        ):
             dvmin = self.to_float(self.vmin)
         elif np.any(finite_values_mask):
             dvmin = self.to_float(np.nanmin(data[finite_values_mask]))
 
-        if self.vmax not in (None, "max"):
+        if self.vmax is not None and not (
+            isinstance(self.vmax, str) and self.vmax == "max"
+        ):
             dvmax = self.to_float(self.vmax)
         elif np.any(finite_values_mask):
             dvmax = self.to_float(np.nanmax(data[finite_values_mask]))


Test patch:
Repository: yt-project/yt

Issue:
BUG: PlotContainer.set_font is broken (color)
### Bug report

**Bug summary**

Setting the text color in a PlotContainer object currently doesn't work

**Code for reproduction**

```python
import yt

ds = yt.load_sample("IsolatedGalaxy")
p = yt.SlicePlot(ds, "z", ("gas", "density"))
p.set_font({"color": "blue"})
```

**Actual outcome**


```python-traceback
Traceback (most recent call last):
  File "/Users/robcleme/dev/yt-project/yt/t.py", line 5, in <module>
    p.set_font({"color": "blue"})
  File "/Users/robcleme/dev/yt-project/yt/yt/visualization/_commons.py", line 121, in newfunc
    retv = f(self, *args, **kwargs)
  File "/Users/robcleme/dev/yt-project/yt/yt/visualization/_commons.py", line 147, in newfunc
    self._setup_plots()
  File "/Users/robcleme/dev/yt-project/yt/yt/visualization/plot_window.py", line 1219, in _setup_plots
    self._set_font_properties()
  File "/Users/robcleme/dev/yt-project/yt/yt/visualization/plot_container.py", line 387, in _set_font_properties
    self.plots[f]._set_font_properties(self._font_properties, self._font_color)
  File "/Users/robcleme/dev/yt-project/yt/yt/visualization/base_plot_types.py", line 201, in _set_font_properties
    label.set_color(self.font_color)
AttributeError: 'WindowPlotMPL' object has no attribute 'font_color'
```



Discussion:
This bug is present as far back as yt 4.0.0. I have not checked older versions.

Resolving patch:
diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -198,7 +198,7 @@ def _set_font_properties(self, font_properties, font_color):
         for label in self._get_labels():
             label.set_fontproperties(font_properties)
             if font_color is not None:
-                label.set_color(self.font_color)
+                label.set_color(font_color)
 
     def _repr_png_(self):
         from ._mpl_imports import FigureCanvasAgg


Test patch:
diff --git a/yt/visualization/tests/test_plotwindow.py b/yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -912,3 +912,19 @@ def test_invalid_swap_projection():
     slc.set_mpl_projection("Robinson")
     slc.swap_axes()  # should raise mylog.warning and not toggle _swap_axes
     assert slc._has_swapped_axes is False
+
+
+def test_set_font():
+    # simply check that calling the set_font method doesn't raise an error
+    # https://github.com/yt-project/yt/issues/4263
+    ds = fake_amr_ds()
+    slc = SlicePlot(ds, "x", "Density")
+    slc.set_font(
+        {
+            "family": "sans-serif",
+            "style": "italic",
+            "weight": "bold",
+            "size": 24,
+            "color": "blue",
+        }
+    )
Repository: yt-project/yt

Issue:
FITS.ds9_region requires pyregion
### Bug report

**Bug summary**

The function `yt.frontends.fits.misc:ds9_region` requires the package pyregion to be installed and fails with a `ModuleNotFoundError` when the function is called. This should make use of the on-demand import mechanism.



Discussion:
related #3270
We migrated away from pyregion in https://github.com/yt-project/yt/pull/4235, but this issue is still relevant and and easy fix, let's clear it out.

Resolving patch:
diff --git a/yt/frontends/fits/misc.py b/yt/frontends/fits/misc.py
--- a/yt/frontends/fits/misc.py
+++ b/yt/frontends/fits/misc.py
@@ -157,9 +157,9 @@ def ds9_region(ds, reg, obj=None, field_parameters=None):
     >>> circle_region = ds9_region(ds, "circle.reg")
     >>> print(circle_region.quantities.extrema("flux"))
     """
-    from regions import Regions
+    from yt.utilities.on_demand_imports import _astropy, _regions
 
-    from yt.utilities.on_demand_imports import _astropy
+    Regions = _regions.Regions
 
     WCS = _astropy.WCS
 
diff --git a/yt/utilities/on_demand_imports.py b/yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -165,6 +165,17 @@ def WCS(self):
 _astropy = astropy_imports()
 
 
+class regions_imports(OnDemand):
+    @safe_import
+    def Regions(self):
+        from regions import Regions
+
+        return Regions
+
+
+_regions = regions_imports()
+
+
 class NotCartopy(NotAModule):
     """
     A custom class to return error messages dependent on system installation


Test patch:
Repository: yt-project/yt

Issue:
BUG: yt.load("~...") doesn't work anymore
### Bug report

**Bug summary**

up until yt 4.0.5, this used to work

```python
import yt

yt.load("~/path/to/my/data")
```
in yt 4.1.x it doesn't (because the `~` is not expanded).

Without running a bisection it seems pretty clear that the breaking change was in #3525, and I can say it wasn't intentional. Luckily the fix is trivial.


Discussion:

Resolving patch:
diff --git a/yt/loaders.py b/yt/loaders.py
--- a/yt/loaders.py
+++ b/yt/loaders.py
@@ -85,7 +85,7 @@ def load(
     yt.utilities.exceptions.YTAmbiguousDataType
         If the data format matches more than one class of similar specilization levels.
     """
-    fn = os.fspath(fn)
+    fn = os.path.expanduser(fn)
 
     if any(wildcard in fn for wildcard in "[]?!*"):
         from yt.data_objects.time_series import DatasetSeries


Test patch:
Repository: yt-project/yt

Issue:
TST: CI instability (setuptools + nose)
### Bug report

**Bug summary**

CI is currently unstable (see https://github.com/yt-project/yt/actions/runs/4180211484) because `setuptools` `67.3` deprecates `pkg_resources.declare_namespace`, which is used by `nose`.
As we know, `nose` is unmaintained so there's no hope that this will be fixed.
The only way I can see to address this rapidly is to filter this deprecation warning.


Discussion:

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -22,6 +22,7 @@
 MPL_VERSION = Version(version("matplotlib"))
 NUMPY_VERSION = Version(version("numpy"))
 PILLOW_VERSION = Version(version("pillow"))
+SETUPTOOLS_VERSION = Version(version("setuptools"))
 
 
 def pytest_addoption(parser):
@@ -84,10 +85,6 @@ def pytest_configure(config):
         # >>> warnings emitted by testing frameworks, or in testing contexts
         # we still have some yield-based tests, awaiting for transition into pytest
         "ignore::pytest.PytestCollectionWarning",
-        # imp is used in nosetest
-        "ignore:the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses:DeprecationWarning",
-        # the deprecation warning message for imp changed in Python 3.10, so we ignore both versions
-        "ignore:the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses:DeprecationWarning",
         # matplotlib warnings related to the Agg backend which is used in CI, not much we can do about it
         "ignore:Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.:UserWarning",
         r"ignore:tight_layout.+falling back to Agg renderer:UserWarning",
@@ -109,6 +106,19 @@ def pytest_configure(config):
     ):
         config.addinivalue_line("filterwarnings", value)
 
+    if find_spec("nose") is not None:
+        # this will be an actual blocker when testing on Python 3.12
+        config.addinivalue_line(
+            "filterwarnings",
+            "ignore:the imp module is deprecated in favour of importlib:DeprecationWarning",
+        )
+
+        if SETUPTOOLS_VERSION >= Version("67.3.0"):
+            config.addinivalue_line(
+                "filterwarnings",
+                r"ignore:Implementing implicit namespace packages \(as specified in PEP 420\) is preferred to `pkg_resources\.declare_namespace`\.:DeprecationWarning",
+            )
+
     if MPL_VERSION < Version("3.5.0"):
         config.addinivalue_line(
             "filterwarnings",


Test patch:
Repository: yt-project/yt

Issue:
TST: CI instability (setuptools + nose)
### Bug report

**Bug summary**

CI is currently unstable (see https://github.com/yt-project/yt/actions/runs/4180211484) because `setuptools` `67.3` deprecates `pkg_resources.declare_namespace`, which is used by `nose`.
As we know, `nose` is unmaintained so there's no hope that this will be fixed.
The only way I can see to address this rapidly is to filter this deprecation warning.


Discussion:
`setuptools` `67.3.2` just broke it again because *they changed the warning message* :/
see https://github.com/pypa/setuptools/pull/3827

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -116,7 +116,9 @@ def pytest_configure(config):
         if SETUPTOOLS_VERSION >= Version("67.3.0"):
             config.addinivalue_line(
                 "filterwarnings",
-                r"ignore:Implementing implicit namespace packages \(as specified in PEP 420\) is preferred to `pkg_resources\.declare_namespace`\.:DeprecationWarning",
+                r"ignore:(Deprecated call to `pkg_resources\.declare_namespace\('mpl_toolkits'\)`\.\n)?"
+                r"Implementing implicit namespace packages \(as specified in PEP 420\) "
+                r"is preferred to `pkg_resources\.declare_namespace`\.:DeprecationWarning",
             )
 
     if MPL_VERSION < Version("3.5.0"):


Test patch:
Repository: yt-project/yt

Issue:
BUG: casting single-element arrays to scalar types is deprecated in future numpy
### Bug report

**Bug summary**

https://github.com/numpy/numpy/pull/10615 was just merged, which breaks a bunch of tests: https://github.com/yt-project/yt/actions/runs/4761003544/jobs/8461853842

Some of the errors are indirectly triggered from matplotlib (I'll report those upstream), but others can be adressed in yt itself.
I fear that dealing with this deprecation may open the door to subtle bugs, so I'll also voice these concerns to numpy dev directly.


Discussion:
Turns out using the `.item()` method on single element arrays is a proper fix that I don't have an issue with, so, I don't need to revive the discussion with numpy dev after all.

Resolving patch:
diff --git a/yt/loaders.py b/yt/loaders.py
--- a/yt/loaders.py
+++ b/yt/loaders.py
@@ -585,7 +585,7 @@ def load_amr_grids(
         get_box_grids_level(
             grid_left_edges[gi, :],
             grid_right_edges[gi, :],
-            grid_levels[gi] + 1,
+            grid_levels[gi].item() + 1,
             grid_left_edges,
             grid_right_edges,
             grid_levels,
diff --git a/yt/visualization/volume_rendering/transfer_functions.py b/yt/visualization/volume_rendering/transfer_functions.py
--- a/yt/visualization/volume_rendering/transfer_functions.py
+++ b/yt/visualization/volume_rendering/transfer_functions.py
@@ -687,7 +687,7 @@ def y_format(y, pos):
         ax.xaxis.set_major_formatter(FuncFormatter(y_format))
         ax.set_xlim(0.0, max_alpha)
         ax.get_xaxis().set_ticks([])
-        ax.set_ylim(visible[0], visible[-1])
+        ax.set_ylim(visible[0].item(), visible[-1].item())
         ax.tick_params(axis="y", colors="white", size=10)
         ax.set_ylabel(label, color="white", size=size * resolution / 512.0)
 


Test patch:
diff --git a/yt/frontends/ramses/tests/test_hilbert.py b/yt/frontends/ramses/tests/test_hilbert.py
--- a/yt/frontends/ramses/tests/test_hilbert.py
+++ b/yt/frontends/ramses/tests/test_hilbert.py
@@ -20,7 +20,7 @@ def test_hilbert3d():
     outputs = [0, 1, 7, 6, 3, 2, 4, 5]
 
     for i, o in zip(inputs, outputs):
-        assert_equal(int(hilbert3d(i, 3)), o)
+        assert_equal(hilbert3d(i, 3).item(), o)
 
 
 output_00080 = "output_00080/info_00080.txt"
Repository: yt-project/yt

Issue:
BUG: setting a boolean parameter via the command line break runtime

### Bug report

**Bug summary**

**Code for reproduction**

```shell
$ yt config set --local yt colored_logs true && python -c "import yt"
```

**Actual outcome**

<!--The output produced by the above code, which may be a screenshot, console
output, etc.-->

```python-traceback
Traceback (most recent call last):
  File "/Users/robcleme/.pyenv/versions/yt-dev/bin/yt", line 8, in <module>
    sys.exit(run_main())
             ^^^^^^^^^^
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 1615, in run_main
    args.func(args)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 228, in run
    self(args)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 1402, in __call__
    set_config(args.section, args.option, args.value, self.config_file)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configure.py", line 195, in set_config
    CONFIG.set(section, *option_path, _cast_value_helper(value))
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configure.py", line 79, in set
    self.config_root.upsert_from_list(
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 54, in upsert_from_list
    next_node.upsert_from_list(next_keys, value, extra_data)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 46, in upsert_from_list
    leaf.value = value
    ^^^^^^^^^^
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 187, in value
    raise TypeError(msg)
TypeError: Error when setting yt.colored_logs.
Tried to assign a value of type <class 'str'>, expected type <class 'bool'>.
This entry was last modified in file: /Users/robcleme/dev/yt-project/yt/yt.toml.
```


One way to patch this would be to special-case `true` and `false` to be interpreted as booleans when received from the command line.


Discussion:

Resolving patch:
diff --git a/yt/utilities/configure.py b/yt/utilities/configure.py
--- a/yt/utilities/configure.py
+++ b/yt/utilities/configure.py
@@ -161,9 +161,9 @@ def _repr_json_(self):
 
 
 def _cast_bool_helper(value):
-    if value == "True":
+    if value in ("true", "True", True):
         return True
-    elif value == "False":
+    elif value in ("false", "False", False):
         return False
     else:
         raise ValueError("Cannot safely cast to bool")


Test patch:
Repository: yt-project/yt

Issue:
BUG: autosetting units for a dimensionless derived field logs unclear warning

### Bug report

**Bug summary**



**Code for reproduction**

```python
import yt

yt.set_log_level("warning")


def _fake_dimless_field(field, data):
    retv = data["index", "x"].d
    return retv

ds = yt.load_sample("IsolatedGalaxy")
ds.add_field(
    ("gas", "fake_field"),
    function=_fake_dimless_field,
    sampling_type="cell",
)
ad = ds.all_data()
ad["gas", "fake_field"]
```

**Actual outcome**

```
yt : [WARNING  ] 2023-06-07 12:25:44,755 Field ('gas', 'fake_field') was added without specifying units or dimensions, auto setting units to
```

**Expected outcome**

the warning should either explicitly state `... to 'dimensionless'` or at least `... to ''`.


Discussion:

Resolving patch:
diff --git a/yt/data_objects/selection_objects/data_selection_objects.py b/yt/data_objects/selection_objects/data_selection_objects.py
--- a/yt/data_objects/selection_objects/data_selection_objects.py
+++ b/yt/data_objects/selection_objects/data_selection_objects.py
@@ -262,9 +262,9 @@ def _generate_fields(self, fields_to_generate):
                         if fi.dimensions is None:
                             mylog.warning(
                                 "Field %s was added without specifying units or dimensions, "
-                                "auto setting units to %s",
+                                "auto setting units to %r",
                                 fi.name,
-                                sunits,
+                                sunits or "dimensionless",
                             )
                         elif fi.dimensions != dimensions:
                             raise YTDimensionalityError(fi.dimensions, dimensions)


Test patch:
Repository: yt-project/yt

Issue:
TST: numpy 1.25 breaks CI (via other dependencies)
### Bug report

**Bug summary**

Some tests are currently failing on deprecation warnings new in numpy 1.25, see: https://github.com/yt-project/yt/actions/runs/5303784716

Importantly, none of the deprecated function calls live in yt itself (we already handled our own), but *other* dependencies (h5py, pandas, pyproj via cartopy) use deprecated API. Let's see what's up with them.

- [ ] [h5py 3.9.0 is about to be released](https://github.com/h5py/h5py/pull/2277) and [has compatibity with numpy 1.25](https://github.com/h5py/h5py/pull/2242), so it may not be worth doing anything about it (unless the release drags for more than a couple days).
- [x] [pandas 2.0.2 is already patched](https://github.com/pandas-dev/pandas/pull/53343), but because `pyart` pinned it to `<2.0`, our CI is effectively stuck on version 1.5.3 . [This is already addressed upstream](https://github.com/ARM-DOE/pyart/pull/1430) -> update: resolved https://github.com/ARM-DOE/pyart/releases/tag/v1.15.2
- [ ] [I've opened a patch on cartopy](https://github.com/SciTools/cartopy/pull/2194)




Discussion:

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -153,6 +153,26 @@ def pytest_configure(config):
             "ignore:invalid value encountered in less_equal:RuntimeWarning",
         )
 
+    if NUMPY_VERSION >= Version("1.25"):
+        if find_spec("cartopy") is not None and (
+            Version(version("cartopy")) <= Version("0.21.1")
+        ):
+            # https://github.com/SciTools/cartopy/pull/2194
+            config.addinivalue_line(
+                "filterwarnings",
+                "ignore:Conversion of an array with ndim > 0 to a scalar is deprecated"
+                ":DeprecationWarning",
+            )
+        if find_spec("h5py") is not None and (
+            Version(version("h5py")) < Version("3.9")
+        ):
+            # https://github.com/h5py/h5py/pull/2242
+            config.addinivalue_line(
+                "filterwarnings",
+                "ignore:`product` is deprecated as of NumPy 1.25.0"
+                ":DeprecationWarning",
+            )
+
     if find_spec("astropy") is not None:
         # at the time of writing, astropy's wheels are behind numpy's latest
         # version but this doesn't cause actual problems in our test suite
@@ -167,7 +187,7 @@ def pytest_configure(config):
         )
 
     if find_spec("cartopy") is not None:
-        # this warning is triggered from cartopy 21.1
+        # this warning is triggered from cartopy 0.21.1
         # see https://github.com/SciTools/cartopy/issues/2113
         SHAPELY_VERSION = Version(version("shapely"))
         if SHAPELY_VERSION >= Version("2.0"):


Test patch: