Skip to content

Commit 5d1d2be

Browse files
authored
Deprecations (#977)
* fixed mailmap for contributors * mnt: removed reshape calls on ndarrays In later versions of numpy array.reshape will be removed. This commit fixes all that. * moved orphan
1 parent 784e42b commit 5d1d2be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+114
-129
lines changed

.mailmap

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@
99
# gives no duplicates.
1010

1111
A.H. Kole <a.h.kole@uu.nl>
12+
A.H. Kole <a.h.kole@uu.nl> <35299166+ahkole@users.noreply.github.com>
1213
Jonas Lundholm Bertelsen <drixi.b@gmail.com>
1314
Jonas Lundholm Bertelsen <drixi.b@gmail.com> Jonas L. B
1415
Jonas Lundholm Bertelsen <drixi.b@gmail.com> Jonas Lundholm Bertelsen <jolub@nanotech.dtu.dk>
16+
Gaetano Calogero <tanocalogero92@gmail.com>
17+
Gaetano Calogero <tanocalogero92@gmail.com> tanocalogero
18+
Isaac Alcon <ialcon8@gmail.com>
19+
Isaac Alcon <ialcon8@gmail.com> <160740748+ialcon@users.noreply.github.com>
1520
Nick Papior <nickpapior@gmail.com>
1621
Nick Papior <nickpapior@gmail.com> Nick Papior Andersen
1722
Nick Papior <nickpapior@gmail.com> Nick R. Papior
23+
Nils Wittemeier <nils.wittemeier@gmail.com>
24+
Nils Wittemeier <nils.wittemeier@gmail.com> <39985259+nils-wittemeier@users.noreply.github.com>
1825
Pol Febrer Calabozo <pfebrer96@gmail.com>
19-
Pol Febrer Calabozo <pfebrer96@gmail.com> pfebrer <42074085+pfebrer@users.noreply.github.com>
20-
Pol Febrer Calabozo <pfebrer96@gmail.com> pfebrer96 <42074085+pfebrer96@users.noreply.github.com>
26+
Pol Febrer Calabozo <pfebrer96@gmail.com> <42074085+pfebrer@users.noreply.github.com>
27+
Pol Febrer Calabozo <pfebrer96@gmail.com> <42074085+pfebrer96@users.noreply.github.com>
2128
Pol Febrer Calabozo <pfebrer96@gmail.com> Pol
2229
Pol Febrer Calabozo <pfebrer96@gmail.com> Pol Febrer
2330
Sofia Sanz Wuhl <sofiasw2@gmail.com>
24-
Sofia Sanz Wuhl <sofiasw2@gmail.com> Sofia Sanz <sofiasw2@gmail.com>
31+
Sofia Sanz Wuhl <sofiasw2@gmail.com> Sofia Sanz
2532
Thomas Frederiksen <thomas_frederiksen@ehu.eus>

changes/orphan.6.fix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed reshape calls, removed from ndarray in later versions

src/sisl/_core/_ufuncs_geometry.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,12 @@ def tile(geometry: Geometry, reps: int, axis: CellAxis) -> Geometry:
815815

816816
# Our first repetition *must* be with
817817
# the former coordinate
818-
xyz = np.tile(geometry.xyz, (reps, 1))
818+
xyz = np.tile(geometry.xyz, (reps, 1)).reshape(reps, geometry.na, 3)
819819
# We may use broadcasting rules instead of repeating stuff
820-
xyz.shape = (reps, geometry.na, 3)
821-
nr = _a.arangei(reps)
822-
nr.shape = (reps, 1, 1)
820+
nr = _a.arangei(reps).reshape(reps, 1, 1)
823821
# Correct the unit-cell offsets
824822
xyz += nr * geometry.cell[axis, :]
825-
xyz.shape = (-1, 3)
823+
xyz = xyz.reshape(-1, 3)
826824

827825
# Create the geometry and return it (note the smaller atoms array
828826
# will also expand via tiling)
@@ -977,15 +975,13 @@ def repeat(geometry: Geometry, reps: int, axis: CellAxis) -> Geometry:
977975

978976
# Our first repetition *must* be with
979977
# the former coordinate
980-
xyz = np.repeat(geometry.xyz, reps, axis=0)
978+
xyz = np.repeat(geometry.xyz, reps, axis=0).reshape(geometry.na, reps, 3)
981979
# We may use broadcasting rules instead of repeating stuff
982-
xyz.shape = (geometry.na, reps, 3)
983-
nr = _a.arangei(reps)
984-
nr.shape = (1, reps)
980+
nr = _a.arangei(reps).reshape(1, reps)
985981
for i in range(3):
986982
# Correct the unit-cell offsets along `i`
987983
xyz[:, :, i] += nr * geometry.cell[axis, i]
988-
xyz.shape = (-1, 3)
984+
xyz = xyz.reshape(-1, 3)
989985

990986
# Create the geometry and return it
991987
return geometry.__class__(xyz, atoms=geometry.atoms.repeat(reps), lattice=lattice)

src/sisl/_core/_ufuncs_sparse_geometry.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def tile(SA: SparseAtom, reps: int, axis: int) -> SparseAtom:
110110

111111
# Create new indptr, indices and D
112112
indptr = _ncol_to_indptr(np.tile(csr.ncol, reps))
113-
indices = _a.emptyi([indptr[-1]])
114-
indices.shape = (reps, -1)
113+
indices = _a.emptyi([indptr[-1]]).reshape(reps, -1)
115114

116115
# Now we should fill the data
117116
isc = geom.a2isc(col)
@@ -265,8 +264,7 @@ def tile(SO: SparseOrbital, reps: int, axis: int) -> SparseOrbital:
265264

266265
# Create new indptr, indices and D
267266
indptr = _ncol_to_indptr(np.tile(ncol, reps))
268-
indices = _a.emptyi([indptr[-1]])
269-
indices.shape = (reps, -1)
267+
indices = _a.emptyi([indptr[-1]]).reshape(reps, -1)
270268

271269
# Now we should fill the data
272270
isc = geom.o2isc(col)
@@ -428,9 +426,9 @@ def sub(SA: SparseAtom, atoms: AtomsIndex) -> SparseAtom:
428426

429427
idx = np.tile(atoms, SA.n_s)
430428
# Use broadcasting rules
431-
idx.shape = (SA.n_s, -1)
429+
idx = idx.reshape(SA.n_s, -1)
432430
idx += (_a.arangei(SA.n_s) * SA.na).reshape(-1, 1)
433-
idx.shape = (-1,)
431+
idx = idx.ravel()
434432

435433
# Now create the new sparse orbital class
436434
S = SA.__class__(geom, SA.dim, SA.dtype, 1, **SA._cls_kwargs())
@@ -470,9 +468,9 @@ def sub(SO: SparseOrbital, atoms: AtomsIndex) -> SparseOrbital:
470468

471469
idx = np.tile(orbs, SO.n_s)
472470
# Use broadcasting rules
473-
idx.shape = (SO.n_s, -1)
471+
idx = idx.reshape(SO.n_s, -1)
474472
idx += (_a.arangei(SO.n_s) * SO.no).reshape(-1, 1)
475-
idx.shape = (-1,)
473+
idx = idx.ravel()
476474

477475
# Now create the new sparse orbital class
478476
S = SO.__class__(geom, SO.dim, SO.dtype, 1, **SO._cls_kwargs())

src/sisl/_core/grid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def index_truncate(self, index):
632632
index = _a.asarrayi(index)
633633
ndim = index.ndim
634634

635-
index.shape = (-1, 3)
635+
index = index.reshape(-1, 3)
636636
log_and_reduce = np.logical_and.reduce
637637
index = index[log_and_reduce(0 <= index, axis=1), :]
638638
s = _a.asarrayi(self.shape).reshape(1, 3)
@@ -679,7 +679,7 @@ def _index_shape(self, shape):
679679
i[:, :, :, 1] = iy.reshape(1, -1, 1)
680680
i[:, :, :, 2] = iz.reshape(1, 1, -1)
681681
del ix, iy, iz
682-
i.shape = (-1, 3)
682+
i = i.reshape(-1, 3)
683683
i = take(i, idx, axis=0)
684684
del idx
685685

@@ -723,7 +723,7 @@ def plane(v1, v2):
723723
i += sa * sc
724724
rxyz[:, i : i + sb * sc, :] += plane(b, c)
725725
del a, b, c, sa, sb, sc
726-
rxyz.shape = (-1, 3)
726+
rxyz = rxyz.reshape(-1, 3)
727727

728728
# Get all indices of the cuboid planes
729729
return self.index(rxyz)

src/sisl/_core/orbital.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ def psi(self, r, m: int = 0):
726726
p[idx] = self.psi_spher(r, theta, phi, m, cos_phi=True)
727727
# Reduce memory immediately
728728
del idx, r, theta, phi
729-
p.shape = s
730-
return p
729+
return p.reshape(s)
731730

732731
def psi_spher(self, r, theta, phi, m: int = 0, cos_phi: bool = False):
733732
r"""Calculate :math:`\phi(|\mathbf r|, \theta, \phi)` at a given point (in spherical coordinates)
@@ -1588,8 +1587,7 @@ def psi(self, r):
15881587
p[idx] = self.psi_spher(r, theta, phi, cos_phi=True)
15891588
# Reduce memory immediately
15901589
del idx, r, theta, phi
1591-
p.shape = s
1592-
return p
1590+
return p.reshape(s)
15931591

15941592
def spher(self, theta, phi, cos_phi: bool = False):
15951593
r"""Calculate the spherical harmonics of this orbital at a given point (in spherical coordinates)

src/sisl/_core/sparse.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,12 +1371,12 @@ def __setitem__(self, key, data):
13711371
ij = broadcast(i, j)
13721372
if data.ndim == 0:
13731373
# enables checking for shape values
1374-
data.shape = (1,)
1374+
data = data.reshape(1)
13751375
elif data.ndim == 1:
13761376
# this corresponds to:
13771377
# [:, :, :] = data.reshape(1, 1, -1)
13781378
if ij.ndim == 2:
1379-
data.shape = (1, -1)
1379+
data = data.reshape(1, -1)
13801380
# if ij.ndim == 1 we shouldn't need
13811381
# to reshape data since it should correspond to each value
13821382
elif data.ndim == 2:
@@ -1400,7 +1400,7 @@ def __setitem__(self, key, data):
14001400
)
14011401
)
14021402
# flatten data
1403-
data.shape = (-1,)
1403+
data = data.ravel()
14041404
# ij.ndim == 1
14051405
# this should correspond to the diagonal specification case
14061406
# and we don't need to do anything
@@ -1410,7 +1410,7 @@ def __setitem__(self, key, data):
14101410
raise ValueError(
14111411
"could not broadcast input array from 3 dimensions into 2"
14121412
)
1413-
data.shape = (-1, data.shape[2])
1413+
data = data.reshape(-1, data.shape[2])
14141414

14151415
# Now we need to figure out the final dimension and how to
14161416
# assign elements.
@@ -1419,7 +1419,7 @@ def __setitem__(self, key, data):
14191419
k = atleast_1d(key[2])
14201420

14211421
if len(k) == 1 and data.ndim == 2:
1422-
data.shape = (-1,)
1422+
data = data.ravel()
14231423

14241424
if data.shape[0] == ij.size:
14251425
for (i, j), d in zip(ij, data):
@@ -1447,9 +1447,9 @@ def __setitem__(self, key, data):
14471447
else:
14481448
# Ensure correct shape
14491449
if data.size == 1:
1450-
data.shape = (1, 1)
1450+
data = data.reshape(1, 1)
14511451
else:
1452-
data.shape = (-1, self.shape[2])
1452+
data = data.reshape(-1, self.shape[2])
14531453

14541454
# Now there are two cases
14551455
if data.shape[0] == 1:

src/sisl/_core/sparse_geometry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def untile(
823823
# division operations.
824824
lsc = tile(self.geometry.lattice.sc_off, (1, reps)).reshape(-1, reps, 3)
825825
lsc[:, :, axis] = lsc[:, :, axis] * reps + _a.arangei(reps) - segment
826-
lsc.shape = (-1, 3)
826+
lsc = lsc.reshape(-1, 3)
827827

828828
# now we have the *correct* lsc that corresponds to the
829829
# sc_off in the cut structure.
@@ -2949,9 +2949,9 @@ def toSparseAtom(self, dim: Optional[int] = None, dtype=None):
29492949

29502950
# Create a conversion vector
29512951
orb2atom = tile(geom.o2a(_a.arangei(geom.no)), geom.n_s)
2952-
orb2atom.shape = (-1, geom.no)
2952+
orb2atom = orb2atom.reshape(-1, geom.no)
29532953
orb2atom += _a.arangei(geom.n_s).reshape(-1, 1) * geom.na
2954-
orb2atom.shape = (-1,)
2954+
orb2atom = orb2atom.ravel()
29552955

29562956
# First convert all rows to the same
29572957
csr = self._csr

src/sisl/_core/tests/test_lattice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ def test_creation_rotate(self, setup):
310310

311311
lattice = Lattice(param)
312312

313-
param.shape = (2, 3)
314-
parama.shape = (2, 3)
313+
param = param.reshape(2, 3)
314+
parama = parama.reshape(2, 3)
315315

316316
assert np.allclose(param, np.array(lattice.parameters()))
317317
assert np.allclose(parama, np.array(lattice.parameters(True)))

src/sisl/_core/tests/test_orbital.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def test_spherical():
3939
xyz = spher2cart(r, theta, phi)
4040
s = xyz.shape[:-1]
4141
r1, theta1, phi1 = cart2spher(xyz)
42-
r1.shape = s
43-
theta1.shape = s
44-
phi1.shape = s
42+
r1 = r1.reshape(s)
43+
theta1 = theta1.reshape(s)
44+
phi1 = phi1.reshape(s)
4545
assert np.allclose(r, r1)
4646
assert np.allclose(theta, theta1[1:2, :, 1:2])
4747
assert np.allclose(phi, phi1[0:1, 0:1, :])

0 commit comments

Comments
 (0)