Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson committed Dec 18, 2023
1 parent d05bcc2 commit 109cf3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
33 changes: 0 additions & 33 deletions ehrapy/io/_utility_io.py

This file was deleted.

28 changes: 27 additions & 1 deletion ehrapy/io/_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 109cf3a

Please sign in to comment.