Skip to content

Commit

Permalink
feat: support no view & view dict (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraalex authored Oct 27, 2023
1 parent 8b6a562 commit b995676
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zeno-client"
version = "0.1.10"
version = "0.1.11"
description = "Python client for creating new Zeno projects and uploading data."
authors = ["Zeno Team <[email protected]>"]
license = "MIT"
Expand Down
27 changes: 19 additions & 8 deletions zeno_client/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Functions to upload data to Zeno's backend."""
import io
import json
import re
import urllib
from importlib.metadata import version as package_version
from json import JSONDecodeError
from typing import List, Optional
from typing import Dict, List, Optional, Union
from urllib.parse import quote

import pandas as pd
Expand Down Expand Up @@ -72,15 +73,15 @@ def upload_dataset(
df: pd.DataFrame,
*,
id_column: str,
data_column: str,
data_column: Optional[str] = None,
label_column: Optional[str] = None,
):
"""Upload a dataset to a Zeno project.
Args:
df (pd.DataFrame): The dataset to upload as a Pandas DataFrame.
id_column (str): Column name containing unique instance IDs.
data_column (str): Column containing the
data_column (str | None, optional): Column containing the
instance data. This can be raw data for data types such as
text, or URLs for large media data such as images and videos.
label_column (str | None, optional): Column containing the
Expand All @@ -89,7 +90,11 @@ def upload_dataset(
if (
id_column == label_column
or id_column == data_column
or label_column == data_column
or (
label_column == data_column
and label_column is not None
and data_column is not None
)
):
raise ValueError(
"ERROR: ID, data, and label column names must be unique."
Expand All @@ -100,7 +105,7 @@ def upload_dataset(
if id_column not in df.columns:
raise ValueError("ERROR: id_column not found in dataframe")

if data_column not in df.columns:
if data_column and data_column not in df.columns:
raise ValueError("ERROR: data_column not found in dataframe")

if label_column and label_column not in df.columns:
Expand Down Expand Up @@ -306,7 +311,7 @@ def create_project(
self,
*,
name: str,
view: str,
view: Union[str, Dict] = "",
description: str = "",
metrics: List[ZenoMetric] = [],
samples_per_page: int = 10,
Expand All @@ -317,8 +322,8 @@ def create_project(
Args:
name (str): The name of the project to be created. The project will be
created under the current user, e.g. username/name.
project: str,
view (str): The view to use for the project.
view (Union[str, Dict], optional): The view to use for the project.
Defaults to "".
description (str, optional): The description of the project. Defaults to "".
metrics (list[ZenoMetric], optional): The metrics to calculate for the
project. Defaults to [].
Expand All @@ -336,8 +341,14 @@ def create_project(
"""
if name == "":
raise ValueError("Project name cannot be empty")

if re.findall("[/]", name):
raise ValueError("Project name cannot contain a '/'.")

# if view is dict, dump to json
if isinstance(view, dict):
view = json.dumps(view)

response = requests.post(
f"{self.endpoint}/api/project",
json={
Expand Down

0 comments on commit b995676

Please sign in to comment.