Automatic dtype=object for ragged input is deprecated for numpy 1.19
Package versions
- conda 4.8.4
- python 3.8.5 (h4d41432_2_cpython on conda_forge)
- numpy 1.19.1 (py38h8854b6b_0 on conda_forge)
- kwant 1.4.2 (py38h2e4ba3f_2 on conda_forge)
Description
When using kwant.plotter.current
or kwant.solvers.common.SMatrix.__init__
(see below), one gets the following deprecation warning:
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
Reason
Numpy changed the behaviour in version 1.19, see https://numpy.org/doc/1.19/release/1.19.0-notes.html#deprecate-automatic-dtype-object-for-ragged-input.
Steps to reproduce
Installing kwant:
conda create -n testkwant
conda activate testkwant
conda install -c conda-forge kwant
Testing with closed_system.py
:
curl https://kwant-project.org/doc/1/_downloads/closed_system.py --output closed_system.py
python closed_system.py
output:
closed_system.py:96: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
kwant.plotter.current(syst, current, colorbar=False)
Testing with superconductor.py
:
curl https://kwant-project.org/doc/1/_downloads/superconductor.py --output superconductor.py
python superconductor.py
output:
~/.conda/envs/testkwant/lib/python3.8/site-packages/kwant/solvers/common.py:820: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
np.array(self.block_offsets)[list(self.in_leads)]
~/.conda/envs/testkwant/lib/python3.8/site-packages/kwant/solvers/common.py:822: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
np.array(self.block_offsets)[list(self.out_leads)]