diff --git a/ehrapy/core/meta_information.py b/ehrapy/core/meta_information.py index 79c42c66..f6edafc5 100644 --- a/ehrapy/core/meta_information.py +++ b/ehrapy/core/meta_information.py @@ -17,19 +17,23 @@ def print_versions(): # pragma: no cover >>> import ehrapy as ep >>> ep.print_versions() """ - session_info.show( - dependencies=True, - html=False, - excludes=[ - "builtins", - "stdlib_list", - "importlib_metadata", - "jupyter_core" - # Special module present if test coverage being calculated - # https://gitlab.com/joelostblom/session_info/-/issues/10 - "$coverage", - ], - ) + try: + session_info.show( + dependencies=True, + html=False, + excludes=[ + "builtins", + "stdlib_list", + "importlib_metadata", + "jupyter_core" + # Special module present if test coverage being calculated + # https://gitlab.com/joelostblom/session_info/-/issues/10 + "$coverage", + ], + ) + except AttributeError: + print("[bold yellow]Unable to fetch versions for one or more dependencies.") + pass def print_version_and_date(*, file=None): # pragma: no cover diff --git a/ehrapy/io/_utility_io.py b/ehrapy/io/_utility_io.py deleted file mode 100644 index f34c2b90..00000000 --- a/ehrapy/io/_utility_io.py +++ /dev/null @@ -1,33 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from pathlib import Path - -supported_extensions = {"csv", "tsv", "h5ad"} - - -def _get_file_extension(file_path: Path) -> str: - """Check whether the argument is a filename. - - Args: - file_path: Path to the file. - - Returns: - File extension of the specified file - """ - ext = file_path.suffixes - - if len(ext) > 2: - ext = ext[-2:] - - if ext and ext[-1][1:] in supported_extensions: - return ext[-1][1:] - raise ValueError( - f"""\ - {file_path!r} does not end on a valid extension. - Please, provide one of the available extensions. - {supported_extensions} - """ - ) diff --git a/ehrapy/io/_write.py b/ehrapy/io/_write.py index 13ca0e28..b4d8ba04 100644 --- a/ehrapy/io/_write.py +++ b/ehrapy/io/_write.py @@ -6,12 +6,13 @@ import numpy as np from ehrapy import settings -from ehrapy.io._utility_io import _get_file_extension from ehrapy.preprocessing._encode import encode if TYPE_CHECKING: from anndata import AnnData +supported_extensions = {"csv", "tsv", "h5ad"} + def write( filename: str | Path, @@ -69,6 +70,31 @@ def write( adata.write(filename, compression=compression, compression_opts=compression_opts) +def _get_file_extension(file_path: Path) -> str: + """Check whether the argument is a filename. + + Args: + file_path: Path to the file. + + Returns: + File extension of the specified file + """ + ext = file_path.suffixes + + if len(ext) > 2: + ext = ext[-2:] + + if ext and ext[-1][1:] in supported_extensions: + return ext[-1][1:] + raise ValueError( + f"""\ + {file_path!r} does not end on a valid extension. + Please, provide one of the available extensions. + {supported_extensions} + """ + ) + + def _get_filename_from_key(key, extension=None) -> Path: """Gets full file name from a key.