Skip to content

Commit

Permalink
Move spotlight.io.pandas to spotlight.dataset.pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Oct 23, 2023
1 parent e57108d commit 01ecccc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 334 deletions.
10 changes: 2 additions & 8 deletions renumics/spotlight/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@
from typing_extensions import TypeGuard

from renumics.spotlight.__version__ import __version__
from renumics.spotlight.io.pandas import (
infer_dtypes,
prepare_column,
is_string_mask,
stringify_columns,
)
from .pandas import create_typed_series, infer_dtypes, is_string_mask, prepare_column
from renumics.spotlight.typing import (
BoolType,
IndexType,
Expand All @@ -47,7 +42,6 @@
is_integer,
is_iterable,
)
from renumics.spotlight.io.pandas import create_typed_series
from renumics.spotlight.dtypes.conversion import prepare_path_or_url
from renumics.spotlight import dtypes as spotlight_dtypes

Expand Down Expand Up @@ -738,7 +732,7 @@ def from_pandas(
df = df.reset_index(level=df.index.names) # type: ignore
else:
df = df.copy()
df.columns = pd.Index(stringify_columns(df))
df.columns = pd.Index([str(column) for column in df.columns])

if dtypes is None:
dtypes = {}
Expand Down
16 changes: 13 additions & 3 deletions renumics/spotlight/dtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

__all__ = [
"CategoryDType",
"ArrayDType",
"EmbeddingDType",
"Sequence1DDType",
"bool_dtype",
"int_dtype",
Expand Down Expand Up @@ -83,7 +85,7 @@ def __init__(

def __eq__(self, other: Any) -> bool:
if isinstance(other, CategoryDType):
return other._name == self._name and other._categories == self._categories
return other._categories == self._categories
return False

def __hash__(self) -> int:
Expand Down Expand Up @@ -117,7 +119,7 @@ def __init__(self, shape: Optional[Tuple[Optional[int], ...]] = None):

def __eq__(self, other: Any) -> bool:
if isinstance(other, ArrayDType):
return other._name == self._name and other.shape == self.shape
return other.shape == self.shape
return False

def __hash__(self) -> int:
Expand Down Expand Up @@ -145,7 +147,7 @@ def __init__(self, length: Optional[int] = None):

def __eq__(self, other: Any) -> bool:
if isinstance(other, EmbeddingDType):
return other._name == self._name and other.length == self.length
return other.length == self.length
return False

def __hash__(self) -> int:
Expand All @@ -165,6 +167,14 @@ def __init__(self, x_label: str = "x", y_label: str = "y"):
self.x_label = x_label
self.y_label = y_label

def __eq__(self, other: Any) -> bool:
if isinstance(other, Sequence1DDType):
return other.x_label == self.x_label and other.y_label == self.y_label
return False

def __hash__(self) -> int:
return hash(self._name) ^ hash(self.x_label) ^ hash(self.y_label)


ALIASES: Dict[Any, DType] = {}

Expand Down
16 changes: 16 additions & 0 deletions renumics/spotlight/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
Reading and writing of different data formats.
"""
import ast
from contextlib import suppress
from typing import Any

from .audio import (
get_format_codec,
Expand All @@ -19,6 +22,8 @@
decode_gltf_arrays,
encode_gltf_array,
)
from .huggingface import prepare_hugging_face_dict


__all__ = [
"get_format_codec",
Expand All @@ -34,4 +39,15 @@
"check_gltf",
"decode_gltf_arrays",
"encode_gltf_array",
"prepare_hugging_face_dict",
"try_literal_eval",
]


def try_literal_eval(x: str) -> Any:
"""
Try to evaluate a literal expression, otherwise return value as is.
"""
with suppress(Exception):
return ast.literal_eval(x)
return x
Loading

0 comments on commit 01ecccc

Please sign in to comment.