Repository: pyqtgraph/pyqtgraph

Issue:
Numpy deprecation warning (Numpy v1.20.0 and up)
### Short description
When creating an ImageView, np.int is used. This is deprecated from 1.20.0 and up (current version of Numpy is 1.20.3). See stacktrace for details.

### Expected behavior
No warning should be thrown.

### Real behavior
When launching PyQtGraph within a Qt application, the `ImageView` gives a warning causing my application to crash.
```
Exception                                 Traceback (most recent call last)
~\Desktop\Fluid Physics 2021\imagep.py in gui(path, origin, calibration, unit, color, frame, auto_progress, auto_progress_frame_interval)
    491         image = cv2.imread(path)
--> 492         if image is None: raise Exception
    493         # Convert image data to RGB

Exception: 

During handling of the above exception, another exception occurred:

DeprecationWarning                        Traceback (most recent call last)
<ipython-input-10-38a6421969b6> in <module>
      5 group = groups[group_id]
      6 for file_id, file in enumerate(listdir(f'./fluids-b-data-2/{group}')):
----> 7     height_data = gui(f'./fluids-b-data-2/{group}/{file}', origin=origins[group_id], calibration=calibrations[group_id], color='r', unit='cm')[:,1]
      8     jet_height.append(abs(height_data[0]-height_data[1]))
      9     print(group_id, file_id, jet_height)

~\Desktop\Fluid Physics 2021\imagep.py in gui(path, origin, calibration, unit, color, frame, auto_progress, auto_progress_frame_interval)
    520         else: app = QtWidgets.QApplication.instance()
    521         window = VideoWindow(capture, origin, calibration, unit, color, frame, auto_progress, auto_progress_frame_interval)
--> 522         window.init_video_gui()
    523         window.show()
    524         app.exec_()

~\Desktop\Fluid Physics 2021\imagep.py in init_video_gui(self)
    423         """Initialize the video GUI"""
    424         # First initialize the image GUI, then add to that:
--> 425         self.init_gui()
    426 
    427         # Connect to the necessary events

~\Desktop\Fluid Physics 2021\imagep.py in init_gui(self)
    287         # Put plot in main layout
    288         layout = QtWidgets.QVBoxLayout(self._main)
--> 289         self.plotwidget = PlotWidget(self)
    290 
    291         self.plotwidget.point_remove_last_event.connect(self.point_remove_last_listener)

~\Desktop\Fluid Physics 2021\imagep.py in __init__(self, window)
    104         layout.addWidget(self._plt, 0, 0, 5, 1)
    105 
--> 106         self.lut.setImageItem(self.img)
    107 
    108         # Settings (with title)

C:\Program Files (x86)\Python37-32\lib\site-packages\pyqtgraph\graphicsItems\HistogramLUTItem.py in setImageItem(self, img)
    168         self._setImageLookupTable()
    169         self.regionChanged()
--> 170         self.imageChanged(autoLevel=True)
    171 
    172     def viewRangeChanged(self):

C:\Program Files (x86)\Python37-32\lib\site-packages\pyqtgraph\graphicsItems\HistogramLUTItem.py in imageChanged(self, autoLevel, autoRange)
    222             # plot one histogram for all image data
    223             profiler = debug.Profiler()
--> 224             h = self.imageItem().getHistogram()
    225             profiler('get histogram')
    226             if h[0] is None:

C:\Program Files (x86)\Python37-32\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py in getHistogram(self, bins, step, perChannel, targetImageSize, targetHistogramSize, **kwds)
    526                 bins = []
    527                 if step > 0.0:
--> 528                     bins = self._xp.arange(mn, mx + 1.01 * step, step, dtype=self._xp.int)
    529             else:
    530                 # for float data, let numpy select the bins.

C:\Program Files (x86)\Python37-32\lib\site-packages\numpy\__init__.py in __getattr__(attr)
    285                 pass
    286             else:
--> 287                 warnings.warn(msg, DeprecationWarning, stacklevel=2)
    288                 return val
    289 

DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

```

### Tested environment(s)
 * PyQtGraph version: 0.12.1
 * Qt Python binding: PyQt5 5.13.1 Qt 5.13.1
 * Python version: 3.7.4
 * NumPy version: 1.20.3
 * Operating system:  Windows
 * Installation method: pip


Discussion:
I was catching warnings as errors, silly me. My application doesn't crash anymore! 🥳 
However, it might still be a good idea to fix this warning so I'll keep this issue ticket open for now.
We patched up our uses of np.int and np.float some time ago in #1573 (this was incorporated into the 0.12.1 release I'm fairly sure). 

Doing a search within our library, I'm not seeing other places where we use those deprecated numpy dtypes. 

I'm going to close out the issue, but if you see a place in the library that we still make use of those deprecated dtypes, let me know and we'll patch them up.
Reopening because the traceback here shows there's one still kicking around:

https://github.com/pyqtgraph/pyqtgraph/blob/775f1d629c9f31404f805b3a54bce705cce652db/pyqtgraph/graphicsItems/ImageItem.py#L903

The tricky part is that it's not going to match a search for `np.int` because there's the handling of numpy vs. cupy. I believe this one can safely be changed to `int`.
nice catch!
> Reopening because the traceback here shows there's one still kicking around:
> 
> https://github.com/pyqtgraph/pyqtgraph/blob/775f1d629c9f31404f805b3a54bce705cce652db/pyqtgraph/graphicsItems/ImageItem.py#L903
> 
> The tricky part is that it's not going to match a search for `np.int` because there's the handling of numpy vs. cupy. I believe this one can safely be changed to `int`.

going to tag @outofculture for input as this may have some potential issues with CuPy.
CuPy won't have any problems with using the builtin. Do it.

Resolving patch:
diff --git a/pyqtgraph/graphicsItems/ImageItem.py b/pyqtgraph/graphicsItems/ImageItem.py
--- a/pyqtgraph/graphicsItems/ImageItem.py
+++ b/pyqtgraph/graphicsItems/ImageItem.py
@@ -900,7 +900,7 @@ def getHistogram(self, bins='auto', step='auto', perChannel=False, targetImageSi
                 step = int(self._xp.ceil((mx - mn) / 500.))
                 bins = []
                 if step > 0.0:
-                    bins = self._xp.arange(mn, mx + 1.01 * step, step, dtype=self._xp.int)
+                    bins = self._xp.arange(mn, mx + 1.01 * step, step, dtype=int)
             else:
                 # for float data, let numpy select the bins.
                 bins = self._xp.linspace(mn, mx, 500)


Test patch: