Skip to content

Commit

Permalink
Remove deprecated type argument to anndata constructor (#1126)
Browse files Browse the repository at this point in the history
* Remove deprecated type argument to anndata constructor

* Release note
  • Loading branch information
ivirshup authored Sep 8, 2023
1 parent 430cf4d commit f3e9c32
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
21 changes: 2 additions & 19 deletions anndata/_core/anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,11 @@ def __init__(
varm: np.ndarray | Mapping[str, Sequence[Any]] | None = None,
layers: Mapping[str, np.ndarray | sparse.spmatrix] | None = None,
raw: Mapping[str, Any] | None = None,
dtype: np.dtype | type | str | None = None,
*,
shape: tuple[int, int] | None = None,
filename: PathLike | None = None,
filemode: Literal["r", "r+"] | None = None,
asview: bool = False,
*,
obsp: np.ndarray | Mapping[str, Sequence[Any]] | None = None,
varp: np.ndarray | Mapping[str, Sequence[Any]] | None = None,
oidx: Index1D = None,
Expand All @@ -367,7 +366,6 @@ def __init__(
varm=varm,
raw=raw,
layers=layers,
dtype=dtype,
shape=shape,
obsp=obsp,
varp=varp,
Expand Down Expand Up @@ -443,7 +441,7 @@ def _init_as_actual(
obsp=None,
raw=None,
layers=None,
dtype=None,
*,
shape=None,
filename=None,
filemode=None,
Expand Down Expand Up @@ -516,21 +514,6 @@ def _init_as_actual(
if shape is not None:
raise ValueError("`shape` needs to be `None` if `X` is not `None`.")
_check_2d_shape(X)
# if type doesn’t match, a copy is made, otherwise, use a view
if dtype is not None:
warnings.warn(
"The dtype argument will be deprecated in anndata 0.10.0",
PendingDeprecationWarning,
)
if issparse(X) or isinstance(X, ma.MaskedArray):
# TODO: maybe use view on data attribute of sparse matrix
# as in readwrite.read_10x_h5
if X.dtype != np.dtype(dtype):
X = X.astype(dtype)
elif isinstance(X, (ZarrArray, DaskArray)):
X = X.astype(dtype)
else: # is np.ndarray or a subclass, convert to true np.ndarray
X = np.array(X, dtype, copy=False)
# data matrix and shape
self._X = X
n_obs, n_vars = X.shape
Expand Down
24 changes: 0 additions & 24 deletions anndata/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,6 @@ def test_obsvar_vector_Xlayer(adata):
adata.obs_vector("a", layer="X")


# This should break in 0.9
def test_dtype_warning():
# Tests a warning is thrown
with pytest.warns(PendingDeprecationWarning):
a = AnnData(np.ones((3, 3)), dtype=np.float32)
assert a.X.dtype == np.float32

# This shouldn't warn, shouldn't copy
with warnings.catch_warnings(record=True) as record:
b_X = np.ones((3, 3), dtype=np.float64)
b = AnnData(b_X)
assert not record
assert b_X is b.X
assert b.X.dtype == np.float64

# Should warn, should copy
with pytest.warns(PendingDeprecationWarning):
c_X = np.ones((3, 3), dtype=np.float32)
c = AnnData(c_X, dtype=np.float64)
assert not record
assert c_X is not c.X
assert c.X.dtype == np.float64


def test_deprecated_write_attribute(tmp_path):
pth = tmp_path / "file.h5"
A = np.random.randn(20, 10)
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/0.10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
```

* {meth}`anndata.AnnData.transpose` no longer copies unnecessarily. If you rely on the copying behavior, call `.copy` on the resulting object. {pr}`1114` {user}`ivirshup`
* Removal of deprecated `dtype` argument to `AnnData` constructor {pr}`1126` {user}`ivirshup`

```{rubric} Other updates
```
Expand Down

0 comments on commit f3e9c32

Please sign in to comment.