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

Issue:
specific values for scale parameter can break dims
## 🐛 Bug
haven't dug deeper yet, but reposting here from
https://forum.image.sc/t/image-layer-in-napari-showing-the-wrong-dimension-size-one-plane-is-missing/69939/10


```python
d = np.random.rand(5, 170, 240)
viewer = napari.view_image(d, scale=[3.533, 1.0, 1.0])
```

slider only has 4 positions (not 5) ... where a slightly different first scale value works fine


Discussion:
This issue has been mentioned on **Image.sc Forum**. There might be relevant details there:

https://forum.image.sc/t/image-layer-in-napari-showing-the-wrong-dimension-size-one-plane-is-missing/69939/12

Found the problem. In short:

```py
(17.665-0.0) // 3.533 == 4.0  # what we do in `Dims.nsteps`
(17.665-0.0) / 3.533 == 5.0  # what apparently we should do
```

Some floating point error that's so small it's not even displayed, I suppose. The result of the above expression is passed to `int()`, so it's floored anyways... so I supposed we don't need the floor division. But this makes me wonder if the opposite case can happen as well? (i.e: we "spill" into the next integer)

Resolving patch:
diff --git a/napari/components/dims.py b/napari/components/dims.py
--- a/napari/components/dims.py
+++ b/napari/components/dims.py
@@ -155,7 +155,7 @@ def _check_dims(cls, values):
     def nsteps(self) -> Tuple[int, ...]:
         """Tuple of int: Number of slider steps for each dimension."""
         return tuple(
-            int((max_val - min_val) // step_size)
+            int((max_val - min_val) / step_size)
             for min_val, max_val, step_size in self.range
         )
 


Test patch:
diff --git a/napari/components/_tests/test_dims.py b/napari/components/_tests/test_dims.py
--- a/napari/components/_tests/test_dims.py
+++ b/napari/components/_tests/test_dims.py
@@ -294,3 +294,10 @@ def test_changing_focus():
     assert dims.last_used == 0
     dims._focus_down()
     assert dims.last_used == 2
+
+
+def test_floating_point_edge_case():
+    # see #4889
+    dims = Dims(ndim=2)
+    dims.set_range(0, (0.0, 17.665, 3.533))
+    assert dims.nsteps[0] == 5
Repository: napari/napari

Issue:
Deleting alternative keybinding in preferences also removes first keybinding
## 🐛 Bug

Deleting an alternative keybinding in the interface removes both the second shortcut and the first 

this feature was added in #5018 and this bug should be fixed for 0.4.17

https://user-images.githubusercontent.com/7307488/191619079-0f939e14-99d9-4f91-9dfe-6983d5b0a86d.mp4

cc @Czaki

## To Reproduce

Steps to reproduce the behavior:

1. add an alternative keybinding in preferences
2. delete that keybinding with the 'backspace' key



Discussion:

Resolving patch:
diff --git a/napari/_qt/widgets/qt_keyboard_settings.py b/napari/_qt/widgets/qt_keyboard_settings.py
--- a/napari/_qt/widgets/qt_keyboard_settings.py
+++ b/napari/_qt/widgets/qt_keyboard_settings.py
@@ -409,36 +409,28 @@ def _set_keybinding(self, row, col):
                 elif ind < len(shortcuts_list):
                     shortcuts_list.pop(col - self._shortcut_col)
                 new_value_dict = {}
-                if new_shortcut != "":
-                    # Bind the new shortcut.
-                    try:
-                        for short in shortcuts_list:
-                            action_manager.bind_shortcut(current_action, short)
-                    except TypeError:
-                        self._show_bind_shortcut_error(
-                            current_action,
-                            current_shortcuts,
-                            row,
-                            new_shortcut,
-                        )
-                        return
-
-                    # The new shortcut is valid and can be displayed in widget.
-
-                    # Keep track of what changed.
-                    new_value_dict = {current_action: shortcuts_list}
-
-                    # Format new shortcut.
-
-                elif action_manager._shortcuts[current_action]:
-                    # There is not a new shortcut to bind.  Keep track of it.
-                    new_value_dict = {current_action: shortcuts_list}
+                # Bind the new shortcut.
+                try:
+                    for short in shortcuts_list:
+                        action_manager.bind_shortcut(current_action, short)
+                except TypeError:
+                    self._show_bind_shortcut_error(
+                        current_action,
+                        current_shortcuts,
+                        row,
+                        new_shortcut,
+                    )
+                    return
+
+                # The new shortcut is valid and can be displayed in widget.
+
+                # Keep track of what changed.
+                new_value_dict = {current_action: shortcuts_list}
 
                 self._restore_shortcuts(row)
 
-                if new_value_dict:
-                    # Emit signal when new value set for shortcut.
-                    self.valueChanged.emit(new_value_dict)
+                # Emit signal when new value set for shortcut.
+                self.valueChanged.emit(new_value_dict)
 
     def _show_warning_icons(self, rows):
         """Creates and displays the warning icons.


Test patch:
Repository: napari/napari

Issue:
[test-bot] Benchmark tests failing
The Benchmarks workflow failed on 2022-10-02 08:17 UTC

The most recent failing test was on macos-latest py3.9 Qt
with commit: 3bf872cbb1df98665fdb7d5e0f3e1a4845a84202

Full run: https://github.com/napari/napari/actions/runs/3167537281

(This post will be updated if another test fails, as long as this issue remains open.)



Discussion:
I think this is due to https://github.com/napari/napari/pull/4987#issuecomment-1268321263 


Resolving patch:
diff --git a/napari/benchmarks/benchmark_slicing.py b/napari/benchmarks/benchmark_qt_slicing.py
similarity index 100%
rename from napari/benchmarks/benchmark_slicing.py
rename to napari/benchmarks/benchmark_qt_slicing.py


Test patch:
Repository: napari/napari

Issue:
screenshot breaks due to `float` canvas size
This is caused by a new argument in `v0.4.17` called `size=` that lets setting a specific size to the screenshot. I'm sure it used to work, but now this fails:

```py
import napari
v = napari.Viewer()
v.screenshot('test.jpg', size=(10, 10))
```

with the following error:

```py
File ~/venv/napari/lib/python3.10/site-packages/vispy/app/backends/_qt.py:451, in QtBaseCanvasBackend._vispy_set_size(self, w, h)
    449 def _vispy_set_size(self, w, h):
    450     # Set size of the widget or window
--> 451     self.resize(w, h)

TypeError: arguments did not match any overloaded call:
  resize(self, QSize): argument 1 has unexpected type 'float'
  resize(self, int, int): argument 1 has unexpected type 'float'
```


Discussion:
@andy-sweet I added the v0.4.17 milestone, I don't think we want to add a new broken argument :P

Resolving patch:
diff --git a/napari/_qt/qt_main_window.py b/napari/_qt/qt_main_window.py
--- a/napari/_qt/qt_main_window.py
+++ b/napari/_qt/qt_main_window.py
@@ -1272,12 +1272,13 @@ def _screenshot(
                     )
                 # Scale the requested size to account for HiDPI
                 size = tuple(
-                    dim / self._qt_window.devicePixelRatio() for dim in size
+                    int(dim / self._qt_window.devicePixelRatio())
+                    for dim in size
                 )
                 canvas.size = size[::-1]  # invert x ad y for vispy
             if scale is not None:
                 # multiply canvas dimensions by the scale factor to get new size
-                canvas.size = tuple(dim * scale for dim in canvas.size)
+                canvas.size = tuple(int(dim * scale) for dim in canvas.size)
             try:
                 img = self._qt_viewer.canvas.native.grabFramebuffer()
                 if flash:
diff --git a/napari/_vispy/canvas.py b/napari/_vispy/canvas.py
--- a/napari/_vispy/canvas.py
+++ b/napari/_vispy/canvas.py
@@ -2,7 +2,6 @@
 """
 from weakref import WeakSet
 
-from qtpy.QtCore import QSize
 from vispy.scene import SceneCanvas, Widget
 
 from ..utils.colormaps.standardize_color import transform_color
@@ -41,7 +40,6 @@ def __init__(self, *args, **kwargs):
         self.max_texture_sizes = get_max_texture_sizes()
 
         self.events.ignore_callback_errors = False
-        self.native.setMinimumSize(QSize(200, 200))
         self.context.set_depth_func('lequal')
 
     @property


Test patch:
diff --git a/napari/_tests/test_viewer.py b/napari/_tests/test_viewer.py
--- a/napari/_tests/test_viewer.py
+++ b/napari/_tests/test_viewer.py
@@ -165,6 +165,10 @@ def test_screenshot(make_napari_viewer):
     screenshot = viewer.screenshot(canvas_only=False, flash=False)
     assert screenshot.ndim == 3
 
+    # test size argument (and ensure it coerces to int)
+    screenshot = viewer.screenshot(canvas_only=True, size=(20, 20.0))
+    assert screenshot.shape == (20, 20, 4)
+
 
 @skip_on_win_ci
 def test_changing_theme(make_napari_viewer):
Repository: napari/napari

Issue:
New Label Layer emit a warning of invalid color
Since #5180, now that we rely on skimage newer version, we actually see warning about improper colors and colorspace. 

In particular we get "Color data out of range: Z < 0 in N pixels"

The warning in napari emanates from this line:

https://github.com/napari/napari/blob/1cc90a74211c6cbf3fc644da5866f9752cf1ac78/napari/utils/colormaps/colormap_utils.py#L361

And it seem that we are sampling colors outside of the lab space. Skimage goes via the XYZ space, and Z is negative for some of those colors, and then clipped to 0, then converted from XYZ to RGB. 

I'm not sure what the implications are – there are at least some improvement we can send upstream to skimage to tell us _which_ values are incorrect. 

_Originally posted by @Carreau in https://github.com/napari/napari/issues/5180#issuecomment-1306910267_
      


Discussion:

Resolving patch:
diff --git a/napari/utils/colormaps/colormap_utils.py b/napari/utils/colormaps/colormap_utils.py
--- a/napari/utils/colormaps/colormap_utils.py
+++ b/napari/utils/colormaps/colormap_utils.py
@@ -118,12 +118,22 @@ def _all_rgb():
     return np.stack((r, g, b), axis=-1).reshape((-1, 3))
 
 
-# obtained with colorconv.rgb2luv(_all_rgb().reshape((-1, 256, 3)))
+# The following values were precomputed and stored as constants
+# here to avoid heavy computation when importing this module.
+# The following code can be used to reproduce these values.
+#
+# rgb_colors = _all_rgb()
+# luv_colors = colorconv.rgb2luv(rgb_colors)
+# LUVMIN = np.amin(luv_colors, axis=(0,))
+# LUVMAX = np.amax(luv_colors, axis=(0,))
+# lab_colors = colorconv.rgb2lab(rgb_colors)
+# LABMIN = np.amin(lab_colors, axis=(0,))
+# LABMAX = np.amax(lab_colors, axis=(0,))
+
 LUVMIN = np.array([0.0, -83.07790815, -134.09790293])
 LUVMAX = np.array([100.0, 175.01447356, 107.39905336])
 LUVRNG = LUVMAX - LUVMIN
 
-# obtained with colorconv.rgb2lab(_all_rgb().reshape((-1, 256, 3)))
 LABMIN = np.array([0.0, -86.18302974, -107.85730021])
 LABMAX = np.array([100.0, 98.23305386, 94.47812228])
 LABRNG = LABMAX - LABMIN
@@ -358,7 +368,17 @@ def _color_random(n, *, colorspace='lab', tolerance=0.0, seed=0.5):
         elif colorspace == 'rgb':
             raw_rgb = random
         else:  # 'lab' by default
-            raw_rgb = colorconv.lab2rgb(random * LABRNG + LABMIN)
+            # The values in random are in [0, 1], but since the LAB colorspace
+            # is not exactly contained in the unit-box, some 3-tuples might not
+            # be valid LAB color coordinates. scikit-image handles this by projecting
+            # such coordinates into the colorspace, but will also warn when doing this.
+            with warnings.catch_warnings():
+                warnings.filterwarnings(
+                    action='ignore',
+                    message='Color data out of range',
+                    category=UserWarning,
+                )
+                raw_rgb = colorconv.lab2rgb(random * LABRNG + LABMIN)
         rgb = _validate_rgb(raw_rgb, tolerance=tolerance)
         factor *= expand_factor
     return rgb[:n]


Test patch:
Repository: napari/napari

Issue:
[Minor] TransformBoxOverlay value error, no selected_vertex field
## 🐛 Bug

When transforming a label layer a value error occurs due to TransformBoxOverlay not having the field selected_vertex.
Functionality seems not to be affected.

## To Reproduce

Steps to reproduce the behavior:

1. Start napari
2. Create label layer
3. With label layer active, activate transform by pressing 6.
4. Error occurs when moving mouse. 

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
![afbeelding](https://user-images.githubusercontent.com/22346363/217260701-5f7f69e2-c6fe-4e67-8064-a3d2f1cf7480.png)



Discussion:
Hi, checking this maybe what is needed is to change `selected_vertex` to `selected_handle`? Seems like that is the actual name of the attribute defined at:

https://github.com/napari/napari/blob/6416098946d594989072c2044551d7e0eca08328/napari/components/overlays/interaction_box.py#L38-L53

With that change:

![overlay](https://user-images.githubusercontent.com/16781833/229846931-7836e6a4-4bd0-4ce6-ae8f-b41f09444c7d.gif)


Resolving patch:
diff --git a/napari/layers/base/_base_mouse_bindings.py b/napari/layers/base/_base_mouse_bindings.py
--- a/napari/layers/base/_base_mouse_bindings.py
+++ b/napari/layers/base/_base_mouse_bindings.py
@@ -32,7 +32,7 @@ def highlight_box_handles(layer, event):
     nearby_handle = get_nearby_handle(pos, handle_coords)
 
     # set the selected vertex of the box to the nearby_handle (can also be INSIDE or None)
-    layer._overlays['transform_box'].selected_vertex = nearby_handle
+    layer._overlays['transform_box'].selected_handle = nearby_handle
 
 
 def _translate_with_box(


Test patch:
diff --git a/napari/_tests/test_mouse_bindings.py b/napari/_tests/test_mouse_bindings.py
--- a/napari/_tests/test_mouse_bindings.py
+++ b/napari/_tests/test_mouse_bindings.py
@@ -4,6 +4,7 @@
 import numpy as np
 
 from napari._tests.utils import skip_on_win_ci
+from napari.layers.base._base_mouse_bindings import InteractionBoxHandle
 
 
 @skip_on_win_ci
@@ -154,6 +155,24 @@ def move_callback(_layer, event):
     mock_drag.method.assert_called_once()
     mock_release.method.assert_called_once()
     mock_move.method.assert_not_called()
+    mock_press.reset_mock()
+    mock_drag.reset_mock()
+    mock_release.reset_mock()
+
+    # simulate hover in transform mode
+    layer.mode = 'transform'
+    # go to middle of the canvas, so we're sure to be inside
+    position = tuple(d // 2 for d in view.canvas.size)
+    view.canvas.events.mouse_move(pos=position, modifiers=())
+    mock_press.method.assert_not_called()
+    mock_drag.method.assert_not_called()
+    mock_release.method.assert_not_called()
+    mock_move.method.assert_called_once()
+    assert (
+        layer._overlays['transform_box'].selected_handle
+        == InteractionBoxHandle.INSIDE
+    )
+    mock_move.reset_mock()
 
 
 @skip_on_win_ci
Repository: napari/napari

Issue:
3D camera rotation is broken
## 🐛 Bug

It seems we introduced a bug in #5701, according to `git bisect`. The 3D camera rotation is "absolute" instead of relative (i.e: the point you press on the canvas determines the starting point of that rotation).

## To Reproduce

```py
import napari
import numpy as np
v = napari.Viewer(ndisplay=3)
pl = v.add_points(np.random.rand(10, 3) * 100)
```

Then move the camera a few times.


Discussion:
Well... Shit. LOL

Resolving patch:
diff --git a/napari/_vispy/camera.py b/napari/_vispy/camera.py
--- a/napari/_vispy/camera.py
+++ b/napari/_vispy/camera.py
@@ -242,7 +242,8 @@ def viewbox_mouse_event(self, event):
                 self.mouse_zoom
                 and event.type == 'mouse_wheel'
                 or self.mouse_pan
-                and event.type in ('mouse_move', 'mouse_press')
+                and event.type
+                in ('mouse_move', 'mouse_press', 'mouse_release')
             ):
                 super().viewbox_mouse_event(event)
             else:


Test patch:
Repository: napari/napari

Issue:
Defocus from axis label field on slider
## 🐛 Bug

After selecting the axis label field to the left of an axis slider, clicking outside the text entry area does not reliably break the focus of that UI element. Clicking on the image canvas does break the focus, but adjusting the slider itself, opening the console, etc does not.

## To Reproduce

Steps to reproduce the behavior:

1. look at a 3d image
2. click on the axis label text entry field
3. try to break focus of the axis label field.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

focus should break whenever the user clicks anywhere outside that text field.

## Environment

napari: 0.3.7.dev30+gf101ef7
Platform: macOS-10.15.5-x86_64-i386-64bit
Python: 3.8.2 (default, May 6 2020, 02:49:43) [Clang 4.0.1 (tags/RELEASE_401/final)]
Qt: 5.12.5
PyQt5: 5.12.3
NumPy: 1.18.5
SciPy: 1.4.1
Dask: 2.20.0
VisPy: 0.6.4

GL version: 2.1 ATI-3.9.15
MAX_TEXTURE_SIZE: 16384

Plugins:
- napari-plugin-engine: 0.1.5
- svg: 0.1.3



Discussion:
Thanks for flagging @d-v-b, we will look into this! 

Resolving patch:
diff --git a/napari/_qt/qt_main_window.py b/napari/_qt/qt_main_window.py
--- a/napari/_qt/qt_main_window.py
+++ b/napari/_qt/qt_main_window.py
@@ -145,6 +145,10 @@ def __init__(
 
         self.setStatusBar(ViewerStatusBar(self))
 
+        # Prevent QLineEdit based widgets to keep focus even when clicks are
+        # done outside the widget. See #1571
+        self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
+
         settings = get_settings()
 
         # TODO:


Test patch:
Repository: napari/napari

Issue:
When resize brush using key modifier the paint area is inproperly marked
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

In #5753 the resize brush using the key modifier is introduced. But during resize of the brush, the wrong paint place was indicated.  

https://github.com/napari/napari/assets/3826210/4bd42dbc-7c13-42fb-b5b5-fc827891421f

## To Reproduce

Steps to reproduce the behavior:

1. Hold the button for resize brush
2. Change size of brush moving mouse 
3. Click the left button without the release modifier. 


<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

During resizing, either the painting should happen in a marked place or there clicking shouldn't happen.  

<!-- A clear and concise description of what you expected to happen. -->

## Environment

latest main 

## Additional context

<!-- Add any other context about the problem here. -->


@ksofiyuk As author, could you fix this? 


Discussion:

Resolving patch:
diff --git a/napari/layers/labels/_labels_mouse_bindings.py b/napari/layers/labels/_labels_mouse_bindings.py
--- a/napari/layers/labels/_labels_mouse_bindings.py
+++ b/napari/layers/labels/_labels_mouse_bindings.py
@@ -22,6 +22,11 @@ def draw(layer, event):
     pixels will be changed to background and this tool functions like an
     eraser
     """
+
+    # Do not allow drawing while adjusting the brush size with the mouse
+    if layer.cursor == 'circle_frozen':
+        return
+
     coordinates = mouse_event_to_labels_coordinate(layer, event)
     if layer._mode == Mode.ERASE:
         new_label = layer._background_label


Test patch:
Repository: napari/napari

Issue:
[main] Keyboard shortcuts text is low contrast.
## 🐛 Bug

The Action descriptions for Keyboard shortcuts are low contrast and hard to read:
<img width="1232" alt="image" src="https://github.com/napari/napari/assets/76622105/7ffe5f04-cc14-4b43-bb29-767ddc886e31">
<img width="1232" alt="image" src="https://github.com/napari/napari/assets/76622105/9600ec56-ff29-40d0-99a9-2cce189fd419">

## To Reproduce

Steps to reproduce the behavior:

1. Using `main` open the Keyboard Shortcuts Preferences	pane 


## Expected behavior

The previous behavior, with contrasty text:
<img width="1232" alt="image" src="https://github.com/napari/napari/assets/76622105/21efb0e2-fe69-4dd8-bb2a-7aa42b0ab69c">

<img width="1232" alt="image" src="https://github.com/napari/napari/assets/76622105/5f232e7f-6e69-4ffc-8221-da15f69345a9">


## Environment

```
napari: 0.5.0a2.dev129+g0dfb37b4
Platform: macOS-13.3.1-arm64-arm-64bit
System: MacOS 13.3.1
Python: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:12:31) [Clang 14.0.6 ]
Qt: 5.15.6
PyQt5: 5.15.7
NumPy: 1.24.3
SciPy: 1.10.1
Dask: 2023.4.1
VisPy: 0.13.0
magicgui: 0.7.2
superqt: unknown
in-n-out: 0.1.7
app-model: 0.1.4
npe2: 0.7.1.dev19+gabbe752.d20230503

OpenGL:
  - GL version:  2.1 Metal - 83.1
  - MAX_TEXTURE_SIZE: 16384

Screens:
  - screen 1: resolution 1680x1050, scale 2.0

Settings path:
  - /Users/piotrsobolewski/Library/Application Support/napari/napari-dev_a1eb8b76ba95fa16ad06e26097b46b8455dfbf0b/settings.yaml
Plugins:
  - napari: 0.5.0a2.dev109+gd91f4ee5 (77 contributions)
  - napari-console: 0.0.8 (0 contributions)
  - napari-ome-zarr: 0.5.2 (2 contributions)
  - napari-svg: 0.1.6 (2 contributions)

```

## Additional context

macOS arm64, but @Czaki noted that he saw this issue too, locally :
https://github.com/napari/napari/pull/5679#issuecomment-1550354481


Discussion:
Using `git bisect` I get:
d9cb1134ff9dafbf480f4b51d13ef35a94bdf580
PR #5745 as the source of the regression.
I've got a fix, it's because of `item.setFlags(Qt.ItemFlag.NoItemFlags)` in `qt_keyboard_settings`
Will make a PR later.

Resolving patch:
diff --git a/napari/_qt/widgets/qt_keyboard_settings.py b/napari/_qt/widgets/qt_keyboard_settings.py
--- a/napari/_qt/widgets/qt_keyboard_settings.py
+++ b/napari/_qt/widgets/qt_keyboard_settings.py
@@ -230,7 +230,7 @@ def _set_table(self, layer_str: str = ''):
                 shortcuts = action_manager._shortcuts.get(action_name, [])
                 # Set action description.  Make sure its not selectable/editable.
                 item = QTableWidgetItem(action.description)
-                item.setFlags(Qt.ItemFlag.NoItemFlags)
+                item.setFlags(Qt.ItemFlag.ItemIsEnabled)
                 self._table.setItem(row, self._action_name_col, item)
 
                 # Create empty item in order to make sure this column is not


Test patch: