Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

✨ Combine record into DObject #77

Merged
merged 5 commits into from
Dec 9, 2022
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ repos:
hooks:
- id: pydocstyle
args: # google style + __init__, see http://www.pydocstyle.org/en/stable/error_codes.html
- --ignore=D100,D101,D102,D103,D106,D107,D203,D204,D213,D215,D400,D401,D403,D404,D406,D407,D408,D409,D413
- --ignore=D100,D101,D102,D103,D106,D107,D203,D204,D213,D215,D400,D401,D403,D404,D406,D407,D408,D409,D413,D418
79 changes: 78 additions & 1 deletion lnschema_core/_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from datetime import datetime as datetime
from pathlib import Path
from typing import List, Optional, Union
from typing import Any, List, Optional, Union, overload # noqa

import anndata as ad
import pandas as pd
import sqlalchemy as sa
from cloudpathlib import CloudPath
from pydantic.fields import PrivateAttr
Expand Down Expand Up @@ -182,6 +184,81 @@ def path(self) -> Union[Path, CloudPath]:
"""Path on storage."""
return filepath_from_dobject(self)

def load(self, stream: bool = False):
"""Load data object.

Returns object associated with the stored `dobject`.

Populates `RunIn` when called from a notebook.

Guide: https://lamin.ai/docs/db/guide/select-load
"""
from lamindb._load import load as lnload

return lnload(dobject=self, stream=stream)

@overload
def __init__(
self,
data: Union[Path, str, pd.DataFrame, ad.AnnData] = None,
*,
name: Optional[str] = None,
features_ref: Any = None,
source: Optional["Run"] = None,
id: Optional[str] = None,
format: Optional[str] = None,
):
"""Create a DObject record from data."""
...

@overload
def __init__(
self,
id: Optional[str] = None,
name: Optional[str] = None,
source: Optional["Run"] = None,
suffix: Optional[str] = None,
hash: Optional[str] = None,
run_id: Optional[str] = None,
storage_id: Optional[str] = None,
features: List["Features"] = [],
targets: List["Run"] = [],
):
"""Create a DObject record from fields."""
...

def __init__( # type: ignore
self,
data: Union[Path, str, pd.DataFrame, ad.AnnData] = None,
*,
features_ref: Any = None,
source: Optional["Run"] = None,
format: Optional[str] = None,
id: Optional[str] = None,
name: Optional[str] = None,
suffix: Optional[str] = None,
hash: Optional[str] = None,
run_id: Optional[str] = None,
storage_id: Optional[str] = None,
features: List["Features"] = [],
targets: List["Run"] = [],
):
kwargs = locals()
if data is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from lamindb import create_dobject_from_data

from lamindb._record import create_dobject_from_data

record = create_dobject_from_data(
data=data,
name=name,
features_ref=features_ref,
source=source,
id=id,
format=format,
)
kwargs = record.dict()

super().__init__(**kwargs)


class Run(SQLModel, table=True): # type: ignore
"""Code runs that transform data.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dynamic = ["version", "description"]
dependencies = [
"nbproject",
"sqlmodel",
"anndata"
]

[project.urls]
Expand Down