Skip to content

Commit

Permalink
Remove numpy type aliases (#225)
Browse files Browse the repository at this point in the history
* update python version to 3.10

* update numpy version to 1.20

* replace np.float with float per deprecation warning

* replace np.NaN with np.nan for consistency

---------

Co-authored-by: Solstice Cerasus <[email protected]>
  • Loading branch information
dsm-72 and Solstice Cerasus authored May 30, 2023
1 parent 12f1286 commit 7609ea9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build:
image: latest
python:
version: 3.6
version: 3.10
30 changes: 15 additions & 15 deletions diffxpy/testing/det.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def log10_pval_clean(self, log10_threshold=-30):
:param log10_threshold: minimal log10 p-value to return.
:return: Cleaned log10 transformed p-values.
"""
pvals = np.reshape(self.pval, -1).astype(dtype=np.float)
pvals = np.reshape(self.pval, -1).astype(dtype=float)
pvals = np.clip(
pvals,
np.nextafter(0, 1),
Expand All @@ -148,7 +148,7 @@ def log10_qval_clean(self, log10_threshold=-30):
:param log10_threshold: minimal log10 q-value to return.
:return: Cleaned log10 transformed q-values.
"""
qvals = np.reshape(self.qval, -1).astype(dtype=np.float)
qvals = np.reshape(self.qval, -1).astype(dtype=float)
qvals = np.clip(
qvals,
np.nextafter(0, 1),
Expand Down Expand Up @@ -357,7 +357,7 @@ def plot_ma(
plt.ioff()

ave = np.log(np.clip(
self.mean.astype(dtype=np.float),
self.mean.astype(dtype=float),
np.max(np.array([np.nextafter(0, 1), min_mean])),
np.inf
))
Expand Down Expand Up @@ -1564,8 +1564,8 @@ def __init__(
x0, x1 = split_x(data, grouping)

# Only compute p-values for genes with non-zero observations and non-zero group-wise variance.
mean_x0 = np.asarray(np.mean(x0, axis=0)).flatten().astype(dtype=np.float)
mean_x1 = np.asarray(np.mean(x1, axis=0)).flatten().astype(dtype=np.float)
mean_x0 = np.asarray(np.mean(x0, axis=0)).flatten().astype(dtype=float)
mean_x1 = np.asarray(np.mean(x1, axis=0)).flatten().astype(dtype=float)
# Avoid unnecessary mean computation:
self._mean = np.asarray(np.average(
a=np.vstack([mean_x0, mean_x1]),
Expand All @@ -1577,11 +1577,11 @@ def __init__(
self._ave_nonzero = self._mean != 0 # omit all-zero features
if isinstance(x0, scipy.sparse.csr_matrix):
# Efficient analytic expression of variance without densification.
var_x0 = np.asarray(np.mean(x0.power(2), axis=0)).flatten().astype(dtype=np.float) - np.square(mean_x0)
var_x1 = np.asarray(np.mean(x1.power(2), axis=0)).flatten().astype(dtype=np.float) - np.square(mean_x1)
var_x0 = np.asarray(np.mean(x0.power(2), axis=0)).flatten().astype(dtype=float) - np.square(mean_x0)
var_x1 = np.asarray(np.mean(x1.power(2), axis=0)).flatten().astype(dtype=float) - np.square(mean_x1)
else:
var_x0 = np.asarray(np.var(x0, axis=0)).flatten().astype(dtype=np.float)
var_x1 = np.asarray(np.var(x1, axis=0)).flatten().astype(dtype=np.float)
var_x0 = np.asarray(np.var(x0, axis=0)).flatten().astype(dtype=float)
var_x1 = np.asarray(np.var(x1, axis=0)).flatten().astype(dtype=float)
self._var_geq_zero = np.logical_or(
var_x0 > 0,
var_x1 > 0
Expand Down Expand Up @@ -1690,8 +1690,8 @@ def __init__(

x0, x1 = split_x(data, grouping)

mean_x0 = np.asarray(np.mean(x0, axis=0)).flatten().astype(dtype=np.float)
mean_x1 = np.asarray(np.mean(x1, axis=0)).flatten().astype(dtype=np.float)
mean_x0 = np.asarray(np.mean(x0, axis=0)).flatten().astype(dtype=float)
mean_x1 = np.asarray(np.mean(x1, axis=0)).flatten().astype(dtype=float)
# Avoid unnecessary mean computation:
self._mean = np.asarray(np.average(
a=np.vstack([mean_x0, mean_x1]),
Expand All @@ -1702,11 +1702,11 @@ def __init__(
)).flatten()
if isinstance(x0, scipy.sparse.csr_matrix):
# Efficient analytic expression of variance without densification.
var_x0 = np.asarray(np.mean(x0.power(2), axis=0)).flatten().astype(dtype=np.float) - np.square(mean_x0)
var_x1 = np.asarray(np.mean(x1.power(2), axis=0)).flatten().astype(dtype=np.float) - np.square(mean_x1)
var_x0 = np.asarray(np.mean(x0.power(2), axis=0)).flatten().astype(dtype=float) - np.square(mean_x0)
var_x1 = np.asarray(np.mean(x1.power(2), axis=0)).flatten().astype(dtype=float) - np.square(mean_x1)
else:
var_x0 = np.asarray(np.var(x0, axis=0)).flatten().astype(dtype=np.float)
var_x1 = np.asarray(np.var(x1, axis=0)).flatten().astype(dtype=np.float)
var_x0 = np.asarray(np.var(x0, axis=0)).flatten().astype(dtype=float)
var_x1 = np.asarray(np.var(x1, axis=0)).flatten().astype(dtype=float)
self._var_geq_zero = np.logical_or(
var_x0 > 0,
var_x1 > 0
Expand Down
4 changes: 2 additions & 2 deletions diffxpy/testing/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,9 @@ def pairwise(
elif isinstance(data, glm.typing.InputDataBase):
data = data.x
groups = np.unique(grouping)
pvals = np.tile(np.NaN, [len(groups), len(groups), data.shape[1]])
pvals = np.tile(np.nan, [len(groups), len(groups), data.shape[1]])
pvals[np.eye(pvals.shape[0]).astype(bool)] = 0
logfc = np.tile(np.NaN, [len(groups), len(groups), data.shape[1]])
logfc = np.tile(np.nan, [len(groups), len(groups), data.shape[1]])
logfc[np.eye(logfc.shape[0]).astype(bool)] = 0

if keep_full_test_objs:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.14.0
numpy>=1.20.0
scipy
pandas
patsy>=0.5.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
long_description_content_type="text/markdown",
packages=find_packages(),
install_requires=[
'numpy>=1.16.4',
'numpy>=1.20',
'scipy>=1.2.1',
'pandas',
'patsy>=0.5.0',
Expand Down

0 comments on commit 7609ea9

Please sign in to comment.