Skip to content

Commit

Permalink
fixes and bumpver
Browse files Browse the repository at this point in the history
  • Loading branch information
EvangMM committed Mar 15, 2024
1 parent f592dac commit 852e5ca
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 145 deletions.
4 changes: 2 additions & 2 deletions ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-ai"
version = "0.2.28"
version = "0.2.29"
description = "Python SDK for DHCore"
readme = "README.md"
authors = [
Expand All @@ -27,7 +27,7 @@ dependencies = [
exclude = ["modules*"]

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
2 changes: 1 addition & 1 deletion core/digitalhub_core/entities/_builders/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def build_spec(

# Validate arguments
if validate:
kwargs = class_params(**kwargs).dict()
kwargs = class_params(**kwargs).dict(by_alias=True)

return class_spec(**kwargs)

Expand Down
2 changes: 1 addition & 1 deletion core/digitalhub_core/entities/runs/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def results(self) -> dict:
"""
return self.status.get_results()

def outputs(self, as_key: bool = True, as_dict: bool = False) -> list:
def outputs(self, as_key: bool = False, as_dict: bool = False) -> list:
"""
Get run objects results.
Expand Down
2 changes: 1 addition & 1 deletion core/digitalhub_core/entities/runs/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_results(self) -> dict:
"""
return self.results if self.results is not None else {}

def get_outputs(self, as_key: bool = True, as_dict: bool = False) -> list[dict[str, str | dict | Entity]]:
def get_outputs(self, as_key: bool = False, as_dict: bool = False) -> list[dict[str, str | dict | Entity]]:
"""
Get outputs.
Expand Down
4 changes: 2 additions & 2 deletions core/modules/container/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-core-container"
version = "0.2.28"
version = "0.2.29"
description = "Container runtime for DHCore"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -39,7 +39,7 @@ line-length = 120
convention = "numpy"

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
2 changes: 1 addition & 1 deletion core/modules/container/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
digitalhub-core==0.2.28
digitalhub-core==0.2.29
# via digitalhub-core-container (pyproject.toml)
frozenlist==1.4.1
# via
Expand Down
4 changes: 2 additions & 2 deletions core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-core"
version = "0.2.28"
version = "0.2.29"
description = "Python SDK for DHCore"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -64,7 +64,7 @@ line-length = 120
convention = "numpy"

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
1 change: 1 addition & 0 deletions data/digitalhub_data/entities/dataitems/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def dataitem_from_parameters(
labels=labels,
embedded=embedded,
)

spec = build_spec(
kind,
layer_digitalhub="digitalhub_data",
Expand Down
87 changes: 0 additions & 87 deletions data/digitalhub_data/entities/dataitems/entity/dataitem.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,9 @@
from __future__ import annotations

import shutil
import typing
from pathlib import Path

from digitalhub_core.stores.builder import get_default_store, get_store
from digitalhub_core.utils.exceptions import EntityError
from digitalhub_data.entities.dataitems.entity._base import Dataitem

if typing.TYPE_CHECKING:
import pandas as pd


class DataitemDataitem(Dataitem):

"""
Dataitem dataitem.
"""

def as_df(self, file_format: str | None = None, **kwargs) -> pd.DataFrame:
"""
Read dataitem as a pandas DataFrame. If the dataitem is not local, it will be downloaded
to a temporary folder and deleted after the method is executed. If no file_format is passed,
the function will try to infer it from the dataitem.spec.path attribute.
The path of the dataitem is specified in the spec attribute, and must be a store aware path.
If the dataitem is stored on s3 bucket, the path must be s3://<bucket>/<path_to_dataitem>.
If the dataitem is stored on database (Postgres is the only one supported), the path must
be sql://postgres/<database>/<schema>/<dataitem/view>.
Parameters
----------
file_format : str
Format of the file. (Supported csv and parquet).
**kwargs
Keyword arguments.
Returns
-------
pd.DataFrame
Pandas DataFrame.
"""
if self.spec.path is None:
raise EntityError("Path is not specified.")

store = get_store(self.spec.path)
tmp_path = False

# Download dataitem if not local
if not self._check_local(self.spec.path):
path = store.download(self.spec.path)
tmp_path = True
else:
path = self.spec.path

# Check file format and get dataitem as DataFrame
extension = self._get_extension(self.spec.path, file_format)
df = store.read_df(path, extension, **kwargs)

# Delete tmp folder
if tmp_path:
pth = Path(path)
if pth.is_file():
pth = pth.parent
shutil.rmtree(pth)

return df

def write_df(self, target_path: str | None = None, df: pd.DataFrame | None = None, **kwargs) -> str:
"""
Write pandas DataFrame as parquet.
If no target_path is passed, the dataitem will be written into the default store.
If no DataFrame is passed, the dataitem will be written into the target_path.
Parameters
----------
target_path : str
Path to write the dataframe to
df : pd.DataFrame
DataFrame to write.
**kwargs
Keyword arguments.
Returns
-------
str
Path to the written dataframe.
"""
if target_path is None:
target_path = f"{self.project}/dataitems/{self.kind}/{self.name}.parquet"
store = get_default_store()
else:
store = get_store(target_path)
if df is None:
df = self.as_df()
return store.write_df(df, target_path, **kwargs)
25 changes: 11 additions & 14 deletions data/digitalhub_data/entities/dataitems/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ class DataitemSpec(Spec):
Dataitem specifications.
"""

def __init__(self, path: str, schema: dict | None = None, **kwargs) -> None:
def __init__(self, path: str) -> None:
"""
Constructor.
Parameters
----------
path : str
The path of the dataitem.
**kwargs
Keyword arguments.
"""
self.path = path
self.schema = schema

self._any_setter(**kwargs)


class DataitemParams(SpecParams):
Expand All @@ -37,9 +27,6 @@ class DataitemParams(SpecParams):
path: str
"The path of the dataitem."

_schema: dict = Field(alias="schema")
"""The schema of the dataitem in table schema format."""


class DataitemSpecDataitem(DataitemSpec):
"""
Expand All @@ -58,12 +45,22 @@ class DataitemSpecTable(DataitemSpec):
Dataitem table specifications.
"""

def __init__(self, path: str, schema: str | None = None) -> None:
"""
Constructor.
"""
super().__init__(path)
self.schema = schema


class DataitemParamsTable(DataitemParams):
"""
Dataitem table parameters.
"""

schema_: dict = Field(default=None, alias="schema")
"""The schema of the dataitem in table schema format."""


class DataitemSpecIceberg(DataitemSpec):
"""
Expand Down
3 changes: 1 addition & 2 deletions data/modules/dbt/digitalhub_data_dbt/utils/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ def get_schema(columns: tuple) -> list[dict]:
A list of dictionaries containing schema.
"""
try:
schema = [{"name": c.name, "type": TYPE_MAPPER.get(c.type_code, "any")} for c in columns]
return {"schema": schema}
return {"fields": [{"name": c.name, "type": TYPE_MAPPER.get(c.type_code, "any")} for c in columns]}
except Exception:
msg = "Something got wrong during schema parsing."
LOGGER.exception(msg)
Expand Down
4 changes: 2 additions & 2 deletions data/modules/dbt/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-data-dbt"
version = "0.2.28"
version = "0.2.29"
description = "Dbt runtime for DHCore"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -43,7 +43,7 @@ line-length = 120
convention = "numpy"

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
4 changes: 2 additions & 2 deletions data/modules/dbt/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
digitalhub-core==0.2.28
digitalhub-core==0.2.29
# via digitalhub-data
digitalhub-data==0.2.28
digitalhub-data==0.2.29
# via digitalhub-data-dbt (pyproject.toml)
frozenlist==1.4.1
# via
Expand Down
4 changes: 2 additions & 2 deletions data/modules/nefertem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-data-nefertem"
version = "0.2.28"
version = "0.2.29"
description = "Nefertem runtime for DHCore"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -48,7 +48,7 @@ line-length = 120
convention = "numpy"

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
4 changes: 2 additions & 2 deletions data/modules/nefertem/requirements-local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
digitalhub-core==0.2.28
digitalhub-core==0.2.29
# via digitalhub-data
digitalhub-data==0.2.28
digitalhub-data==0.2.29
# via digitalhub-data-nefertem (pyproject.toml)
frozenlist==1.4.1
# via
Expand Down
4 changes: 2 additions & 2 deletions data/modules/nefertem/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
digitalhub-core==0.2.28
digitalhub-core==0.2.29
# via digitalhub-data
digitalhub-data==0.2.28
digitalhub-data==0.2.29
# via digitalhub-data-nefertem (pyproject.toml)
frozenlist==1.4.1
# via
Expand Down
4 changes: 2 additions & 2 deletions data/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-data"
version = "0.2.28"
version = "0.2.29"
description = "Python SDK for DHCore"
readme = "README.md"
authors = [
Expand All @@ -27,7 +27,7 @@ dependencies = [
exclude = ["modules*"]

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
2 changes: 1 addition & 1 deletion data/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
digitalhub-core==0.2.28
digitalhub-core==0.2.29
# via digitalhub-data (pyproject.toml)
frozenlist==1.4.1
# via
Expand Down
2 changes: 1 addition & 1 deletion ml/modules/mlrun/digitalhub_ml_mlrun/utils/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create_dataitem_(mlrun_output: dict) -> Dataitem:
kwargs["name"] = mlrun_output.get("metadata", {}).get("key")
kwargs["kind"] = "table"
kwargs["path"] = mlrun_output.get("spec", {}).get("target_path")
kwargs["schema"] = mlrun_output.get("spec", {}).get("schema", {}).get("fields")
kwargs["schema"] = mlrun_output.get("spec", {}).get("schema", {})

dataitem = create_dataitem(**kwargs)

Expand Down
4 changes: 2 additions & 2 deletions ml/modules/mlrun/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digitalhub-ml-mlrun"
version = "0.2.28"
version = "0.2.29"
description = "Mlrun runtime for DHCore"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -44,7 +44,7 @@ line-length = 120
convention = "numpy"

[tool.bumpver]
current_version = "0.2.28"
current_version = "0.2.29"
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = false
Expand Down
Loading

0 comments on commit 852e5ca

Please sign in to comment.