Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/996.dev.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Refactor non-standard object identity tests.

Refactors `not object is None` to `object is not None` to improve readability and adhere to the standard.
2 changes: 1 addition & 1 deletion src/sisl/_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def _(self, other):

def _composite_name(sep):
def getter(self):
if not self._name is None:
if self._name is not None:
return self._name

# Name is unset, we simply return the other parts
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/_core/_ufuncs_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class NestedList:

def __init__(geometry, idx=None, sort=False):
geometry._idx = []
if not idx is None:
if idx is not None:
geometry.append(idx, sort)

def append(geometry, idx, sort=False):
Expand Down
4 changes: 2 additions & 2 deletions src/sisl/_core/_ufuncs_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def sub(grid: Grid, idx: Union[int, Sequence[int]], axis: CellAxis) -> Grid:
shift_geometry = False
if len(idx) > 1:
if np.allclose(np.diff(idx), 1):
shift_geometry = not grid.geometry is None
shift_geometry = grid.geometry is not None

if shift_geometry:
out = grid._copy_sub(len(idx), axis)
Expand Down Expand Up @@ -193,7 +193,7 @@ def append(grid: Grid, other: GridLike, axis: CellAxis) -> Grid:
shape[axis] += other.shape[axis]
d = grid._sc_geometry_dict()
if "geometry" in d:
if not other.geometry is None:
if other.geometry is not None:
d["geometry"] = d["geometry"].append(other.geometry, axis)
else:
d["geometry"] = other.geometry
Expand Down
6 changes: 3 additions & 3 deletions src/sisl/_core/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _sc_geometry_dict(self):
"""Internal routine for copying the Lattice and Geometry"""
d = dict()
d["lattice"] = self.lattice.copy()
if not self.geometry is None:
if self.geometry is not None:
d["geometry"] = self.geometry.copy()
return d

Expand All @@ -429,7 +429,7 @@ def _copy_sub(self, n, axis, scale_geometry=False):
grid = self.__class__(shape, dtype=self.dtype, **self._sc_geometry_dict())
# Update cell shape (the cell is smaller now)
grid.set_lattice(cell)
if scale_geometry and not self.geometry is None:
if scale_geometry and self.geometry is not None:
geom = self.geometry.copy()
fxyz = geom.fxyz.copy()
geom.set_lattice(grid.lattice)
Expand Down Expand Up @@ -847,7 +847,7 @@ def __str__(self):
s += f"commensurate: [{l[0]} {l[1]} {l[2]}]"
else:
s += "{}".format(str(self.lattice).replace("\n", "\n "))
if not self.geometry is None:
if self.geometry is not None:
s += ",\n {}".format(str(self.geometry).replace("\n", "\n "))
return f"{s}\n}}"

Expand Down
12 changes: 6 additions & 6 deletions src/sisl/_core/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def conv(v):
self._bc = _a.fulli([3, 2], getitem("Unknown"))
old = self._bc.copy()

if not boundary is None:
if boundary is not None:
if isinstance(boundary, (Integral, str, bool)):
try:
getitem(boundary)
Expand Down Expand Up @@ -450,9 +450,9 @@ def set_nsc(
c : int, optional
number of supercells in the third unit-cell vector direction
"""
if not nsc is None:
if nsc is not None:
for i in range(3):
if not nsc[i] is None:
if nsc[i] is not None:
self.nsc[i] = nsc[i]
if a:
self.nsc[0] = a
Expand Down Expand Up @@ -601,7 +601,7 @@ def fit(self, xyz, axes: CellAxes = (0, 1, 2), atol: float = 0.05) -> Lattice:
ireps = np.amax(ix, axis=0) - np.amin(ix, axis=0) + 1

# Reduce the non-set axis
if not axes is None:
if axes is not None:
axes = map(direction, listify(axes))
for ax in (0, 1, 2):
if ax not in axes:
Expand Down Expand Up @@ -857,10 +857,10 @@ def _assert(m, v):
else:
idx = (self.sc_off[:, 0] == sc_off[0]).nonzero()[0]

if not sc_off[1] is None:
if sc_off[1] is not None:
idx = idx[(self.sc_off[idx, 1] == sc_off[1]).nonzero()[0]]

if not sc_off[2] is None:
if sc_off[2] is not None:
idx = idx[(self.sc_off[idx, 2] == sc_off[2]).nonzero()[0]]

return idx
Expand Down
4 changes: 2 additions & 2 deletions src/sisl/_core/sparse_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def iter_nnz(self, atoms: AtomsIndex = None, orbitals=None):
"""
if atoms is not None:
orbitals = self.geometry.a2o(atoms, all=True)
elif not orbitals is None:
elif orbitals is not None:
orbitals = _a.asarrayi(orbitals)
if orbitals is None:
yield from self._csr
Expand Down Expand Up @@ -1890,7 +1890,7 @@ def add(self, other, axis: Optional[int] = None, offset: Coord = (0, 0, 0)):
transfer_idx = _a.arangei(self.geometry.no_s).reshape(-1, self.geometry.no)
transfer_idx += _a.arangei(self.geometry.n_s).reshape(-1, 1) * other.geometry.no
# Remove couplings along axis
if not axis is None:
if axis is not None:
idx = (self.geometry.lattice.sc_off[:, axis] != 0).nonzero()[0]
# Tell the routine to delete these indices
transfer_idx[idx, :] = full_no_s + 1
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def array_replace(array, *replace, **kwargs):
others = []

for idx, val in replace:
if not val is None:
if val is not None:
ar[idx] = val
others.append(np.asarray(idx).ravel())

Expand Down
2 changes: 1 addition & 1 deletion src/sisl/_namedindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, name=None, index=None):

if isinstance(name, str):
self.add_name(name, index)
elif not name is None:
elif name is not None:
for n, i in zip(name, index):
self.add_name(n, i)

Expand Down
4 changes: 2 additions & 2 deletions src/sisl/geom/_category/_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def func(a, b):
# Now we are ready to build our scheme
if value.size == 2:
# do it twice
if not value[0] is None:
if value[0] is not None:
coord_ops.append(
create2(is_frac, is_abs, operator.ge, sdir, value[0])
)
if not value[1] is None:
if value[1] is not None:
coord_ops.append(
create2(is_frac, is_abs, operator.le, sdir, value[1])
)
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/geom/_category/_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def categorize(self, geometry: Geometry, atoms: AtomsIndex = None):
return NullCategory()

# Check if we have a condition
if not self._in is None:
if self._in is not None:
# Get category of neighbors
cat = self._in.categorize(geometry, geometry.asc2uc(idx))
idx = [i for i, c in zip(idx, cat) if not isinstance(c, NullCategory)]
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def read_grid(self, imag=None) -> Grid:
the imaginary part of the grid. If the geometries does not match
an error will be raised.
"""
if not imag is None:
if imag is not None:
if not isinstance(imag, Grid):
imag = Grid.read(imag)

Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/openmx/omx.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def _r_lattice_omx(self, *args, **kwargs):
cell = np.empty([3, 3], np.float64)

lc = self.get("Atoms.UnitVectors")
if not lc is None:
if lc is not None:
for i in range(3):
cell[i, :] = [float(k) for k in lc[i].split()[:3]]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/scaleup/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def read_geometry(self, *args, **kwargs) -> Geometry:
ref = None

restart = super().read_geometry()
if not ref is None:
if ref is not None:
restart.lattice = Lattice(
np.dot(ref.lattice.cell, restart.lattice.cell.T), nsc=restart.nsc
)
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/siesta/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def myplot(ax, title, x, y, E):
ax.plot(x, y[ib, :])
ax.set_ylabel("E-Ef [eV]")
ax.set_xlim(x.min(), x.max())
if not E is None:
if E is not None:
ax.set_ylim(E[0], E[1])

if b.shape[1] == 2:
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/siesta/binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def _xij2system(self, xij, geometry=None, **kwargs):

def get_geom_handle(xij):
atoms = self.read_basis(geometry=geometry, **kwargs)
if not atoms is None:
if atoms is not None:
return Geometry(np.zeros([len(atoms), 3]), atoms)

N = len(xij)
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/siesta/eig.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def myplot(ax, title, y, E, s):
ax.scatter(ik, y[:, ib], s=s)
ax.set_xlabel("k-index")
ax.set_xlim(-0.5, len(y) + 0.5)
if not E is None:
if E is not None:
ax.set_ylim(E[0], E[1])

if E.shape[0] == 2:
Expand Down
6 changes: 3 additions & 3 deletions src/sisl/io/siesta/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1732,15 +1732,15 @@ def _p(flag, found):
if not (FOUND_SCF or FOUND_MD):
# none of these are found
# we request that user does not request any input
if (opt_iscf or (not iscf is None)) or (opt_imd or (not imd is None)):
if (opt_iscf or (iscf is not None)) or (opt_imd or (imd is not None)):
raise SileError(f"{self!s} does not contain MD/SCF charges")

elif not FOUND_SCF:
if opt_iscf or (not iscf is None):
if opt_iscf or (iscf is not None):
raise SileError(f"{self!s} does not contain SCF charges")

elif not FOUND_MD:
if opt_imd or (not imd is None):
if opt_imd or (imd is not None):
raise SileError(f"{self!s} does not contain MD charges")

# if either are options they may hold
Expand Down
4 changes: 2 additions & 2 deletions src/sisl/io/sile.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def get_sile_class(filename, *args, **kwargs):

# searchable rules
eligible_rules = []
if cls is None and not cls_search is None:
if cls is None and cls_search is not None:
# cls has not been set, and fcls is found
# Figure out if fcls is a valid sile, if not
# do nothing (it may be part of the file name)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def __init__(self, filename, mode="r", *args, **kwargs):
comment = kwargs.pop("comment", None)
if isinstance(comment, (list, tuple)):
self._comment = list(comment)
elif not comment is None:
elif comment is not None:
self._comment = [comment]
else:
self._comment = []
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/io/tbtrans/se.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def info(self, elec=None):
elec : str or int
the electrode to request information from
"""
if not elec is None:
if elec is not None:
elec = self._elec(elec)

# Create a StringIO object to retain the information
Expand Down
12 changes: 6 additions & 6 deletions src/sisl/io/tbtrans/tbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def norm(self, atoms=None, orbitals=None, norm: NormType = "none") -> int:
NORM = geom.orbitals[a].sum()
return NORM

if not orbitals is None:
if orbitals is not None:
raise ValueError(
f"{self.__class__.__name__}.norm both atom and orbital cannot be specified!"
)
Expand Down Expand Up @@ -528,7 +528,7 @@ def _DOS(self, DOS, atoms, orbitals, sum, norm) -> ndarray:
if isinstance(orbitals, bool):
if not orbitals:
orbitals = None
if not atoms is None and not orbitals is None:
if atoms is not None and orbitals is not None:
raise ValueError(
"Both atoms and orbitals keyword in DOS request "
"cannot be specified, only one at a time."
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def _sparse_data_to_matrix(self, data, isc=None, orbitals=None) -> csr_matrix:
col = self._value("list_col") - 1

# get subset orbitals
if not orbitals is None:
if orbitals is not None:
orbitals = geom._sanitize_orbs(orbitals)

# select values for all supercells
Expand Down Expand Up @@ -1222,7 +1222,7 @@ def _sparse_data_to_matrix(self, data, isc=None, orbitals=None) -> csr_matrix:
for i in (0, 1, 2):
if nsc[i] == 1:
isc[i] = 0
if not isc[i] is None:
if isc[i] is not None:
nsc[i] = 1

# Small function for creating the supercells allowed
Expand Down Expand Up @@ -2777,7 +2777,7 @@ def info(self, elec: Optional[ElecType] = None):
elec : str or int
the electrode to request information from
"""
if not elec is None:
if elec is not None:
elec = self._elec(elec)

# Create a StringIO object to retain the information
Expand Down Expand Up @@ -3234,7 +3234,7 @@ class DataDOS(argparse.Action):
@collect_action
@ensure_E
def __call__(self, parser, ns, value, option_string=None):
if not value is None:
if value is not None:
# we are storing the spectral DOS
e = ns._tbt._elec(value)
if e not in ns._tbt.elecs:
Expand Down
12 changes: 6 additions & 6 deletions src/sisl/io/tests/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ def test_geometry(sisl_tmp):
grid.write(f)
read = grid.read(f)
assert np.allclose(grid.grid, read.grid)
assert not grid.geometry is None
assert not read.geometry is None
assert grid.geometry is not None
assert read.geometry is not None
assert grid.geometry == read.geometry

# write in another unit
grid.write(f, unit="nm")
read = grid.read(f)
assert np.allclose(grid.grid, read.grid)
assert not grid.geometry is None
assert not read.geometry is None
assert grid.geometry is not None
assert read.geometry is not None
assert grid.geometry == read.geometry


Expand All @@ -75,8 +75,8 @@ def test_imaginary(sisl_tmp):
read_i = grid.read(fi)
read.grid = read.grid + 1j * read_i.grid
assert np.allclose(grid.grid, read.grid)
assert not grid.geometry is None
assert not read.geometry is None
assert grid.geometry is not None
assert read.geometry is not None
assert grid.geometry == read.geometry

read = grid.read(fr, imag=fi)
Expand Down
4 changes: 2 additions & 2 deletions src/sisl/io/tests/test_xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_xsf_geometry(sisl_tmp):
grid = Grid(0.2, geometry=geom)
grid.grid = np.random.rand(*grid.shape)
grid.write(f)
assert not grid.geometry is None
assert grid.geometry is not None


def test_xsf_imaginary(sisl_tmp):
Expand All @@ -73,7 +73,7 @@ def test_xsf_imaginary(sisl_tmp):
grid = Grid(0.2, geometry=geom, dtype=np.complex128)
grid.grid = np.random.rand(*grid.shape) + 1j * np.random.rand(*grid.shape)
grid.write(f)
assert not grid.geometry is None
assert grid.geometry is not None


def test_axsf_geoms(sisl_tmp):
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/physics/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ def Sk(self, format=None):
}
for key in ("gauge",):
val = self.info.get(key, None)
if not val is None:
if val is not None:
opt[key] = val
return self.parent.Sk(**opt)

Expand Down
4 changes: 2 additions & 2 deletions src/sisl/physics/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def eigenvalue(self, k: KPoint = (0, 0, 0), gauge: GaugeType = "lattice", **kwar
for name in ("spin",):
if name in kwargs:
info[name] = kwargs[name]
if not format is None:
if format is not None:
info["format"] = format
return EigenvalueElectron(e, self, **info)

Expand Down Expand Up @@ -413,7 +413,7 @@ def eigenstate(self, k: KPoint = (0, 0, 0), gauge: GaugeType = "lattice", **kwar
for name in ("spin",):
if name in kwargs:
info[name] = kwargs[name]
if not format is None:
if format is not None:
info["format"] = format
# Since eigh returns the eigenvectors [:, i] we have to transpose
return EigenstateElectron(v.T, e, self, **info)
Expand Down
Loading
Loading