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

Value of data is Any. #30

Merged
merged 2 commits into from
Sep 19, 2023
Merged
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
14 changes: 7 additions & 7 deletions src/biocframe/BiocFrame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import OrderedDict
from typing import List, MutableMapping, Optional, Sequence, Tuple, Union
from typing import Any, List, MutableMapping, Optional, Sequence, Tuple, Union

from pandas.api.types import is_numeric_dtype
from prettytable import PrettyTable
Expand Down Expand Up @@ -88,7 +88,7 @@ class BiocFrame:
sliced_bframe = bframe[1:2, [True, False, False]]

Attributes:
data (MutableMapping[str, Union[Sequence, MutableMapping]], optional):
data (MutableMapping[str, Any], optional):
Dictionary of column names as `keys` and their values. all columns must have
the same length. Defaults to None.
number_of_rows (int, optional): Number of rows. Defaults to None.
Expand All @@ -103,7 +103,7 @@ class BiocFrame:

def __init__(
self,
data: Optional[MutableMapping[str, Union[Sequence, MutableMapping]]] = None,
data: Optional[MutableMapping[str, Any]] = None,
number_of_rows: Optional[int] = None,
row_names: Optional[Sequence[str]] = None,
column_names: Optional[Sequence[str]] = None,
Expand Down Expand Up @@ -222,11 +222,11 @@ def row_names(self, names: Optional[Sequence]):
self._row_names = names

@property
def data(self) -> MutableMapping[str, Union[Sequence, MutableMapping]]:
def data(self) -> MutableMapping[str, Any]:
"""Access data as :py:class:`dict`.

Returns:
MutableMapping[str, Union[Sequence, MutableMapping]]:
MutableMapping[str, Any]:
Dictionary of columns and their values.
"""
return self._data
Expand Down Expand Up @@ -306,7 +306,7 @@ def has_column(self, name: str) -> bool:
"""
return name in self.column_names

def column(self, index_or_name: Union[str, int]) -> Union[Sequence, MutableMapping]:
def column(self, index_or_name: Union[str, int]) -> Any:
"""Access a column by integer position or column label.

Args:
Expand All @@ -322,7 +322,7 @@ def column(self, index_or_name: Union[str, int]) -> Union[Sequence, MutableMappi
TypeError: if ``index_or_name`` is neither a string nor an integer.

Returns:
Union[Sequence, MutableMapping]: Column with its original type preserved.
Any: Column with its original type preserved.
"""

return self[:, index_or_name]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_bframe_basic_ops():
assert bframe.column_names is not None
assert len(bframe.column_names) == 3

assert bframe.metadata is None
assert bframe.metadata == {}

assert len(bframe.dims) == 2
assert bframe.dims == (3, 3)
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_bframe_setters():
assert bframe.column_names is not None
assert len(bframe.column_names) == 3

assert bframe.metadata is None
assert bframe.metadata == {}

bframe.metadata = {"a": "b"}
assert bframe.metadata is not None
Expand Down