Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard version API #1318

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions anndata/_io/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from functools import wraps
from importlib.metadata import version
from typing import TYPE_CHECKING, Callable, Literal, Union, cast
from warnings import warn

import h5py
from packaging.version import Version

from .._core.sparse_dataset import BaseCompressedSparseDataset
Expand All @@ -17,7 +17,7 @@

# For allowing h5py v3
# https://github.com/scverse/anndata/issues/442
H5PY_V3 = Version(h5py.__version__).major >= 3
H5PY_V3 = Version(version("h5py")).major >= 3

# -------------------------------------------------------------------------------
# Type conversion
Expand Down
14 changes: 7 additions & 7 deletions anndata/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from collections.abc import Mapping
from contextlib import AbstractContextManager
from dataclasses import dataclass, field
from functools import singledispatch, wraps
from functools import partial, singledispatch, wraps
from importlib.metadata import version
from inspect import Parameter, signature
from pathlib import Path
from typing import Any, Union
Expand Down Expand Up @@ -407,9 +408,8 @@ def _safe_transpose(x):
return x.T


def _map_cat_to_str(cat: pd.Categorical) -> pd.Categorical:
if Version(pd.__version__) >= Version("2.1"):
# Argument added in pandas 2.1
return cat.map(str, na_action="ignore")
else:
return cat.map(str)
if Version(version("pandas")) >= Version("2.1"):
# Argument added in pandas 2.1
_map_cat_to_str = partial(pd.Categorical.map, mapper=str, na_action="ignore")
else:
_map_cat_to_str = partial(pd.Categorical.map, mapper=str)
Loading