Skip to content

Commit

Permalink
fix: connector creation and synthesizer get from api request.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabclmnt committed Feb 7, 2025
1 parent fa42fa0 commit 13bfe6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
10 changes: 4 additions & 6 deletions examples/synthesizers/privacy_example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os

from ydata.sdk.dataset import get_dataset
from ydata.sdk.synthesizers import PrivacyLevel, RegularSynthesizer

# Do not forget to add your token as env variables
os.environ["YDATA_TOKEN"] = '<TOKEN>' # Remove if already defined
os.environ["YDATA_TOKEN"] = '{insert-your-token}' # Remove if already defined

from ydata.sdk.dataset import get_dataset
from ydata.sdk.synthesizers import PrivacyLevel, RegularSynthesizer

def main():
"""In this example, we demonstrate how to train a synthesizer
Expand All @@ -16,12 +15,11 @@ def main():

# We initialize a regular synthesizer
# As long as the synthesizer does not call `fit`, it exists only locally
synth = RegularSynthesizer()
synth = RegularSynthesizer(name='Titanic Privacy')

# We train the synthesizer on our dataset setting the privacy level to high
synth.fit(
X,
name="titanic_synthesizer",
privacy_level=PrivacyLevel.HIGH_PRIVACY
)

Expand Down
10 changes: 8 additions & 2 deletions src/ydata/sdk/connectors/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ def __init__(
self, connector_type: Union[ConnectorType, str, None] = None, credentials: Optional[Dict] = None,
name: Optional[str] = None, project: Optional[Project] = None, client: Optional[Client] = None):
self._init_common(client=client)
self._model = _connector_type_to_model(ConnectorType._init_connector_type(connector_type))._create_model(
connector_type, credentials, name, client=client)

self._model = self.create(connector_type=connector_type,
credentials=credentials,
name=name, project=project,
client=client)

#self._model = _connector_type_to_model(ConnectorType._init_connector_type(connector_type))._create_model(
# connector_type, credentials, name, client=client)

self._project = project

Expand Down
6 changes: 3 additions & 3 deletions src/ydata/sdk/synthesizers/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ def _sample(self, payload: Dict) -> pdDataFrame:
response = self._client.post(
f"/synthesizer/{self.uid}/sample", json=payload, project=self._project)

data: Dict = response.json()
sample_uid = data.get('uid')
data = response.json()
sample_uid: str = data.get('uid')
sample_status = None
while sample_status not in ['finished', 'failed']:
self._logger.info('Sampling from the synthesizer...')
response = self._client.get(
f'/synthesizer/{self.uid}/history', project=self._project)
history: Dict = response.json()
history: list = response.json()
sample_data = next((s for s in history if s.get('uid') == sample_uid), None)
sample_status = sample_data.get('status', {}).get('state')
sleep(BACKOFF)
Expand Down
2 changes: 1 addition & 1 deletion src/ydata/sdk/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_datasource_info(dataframe, datatype):
nrows, ncols = dataframe.shape[0], dataframe.shape[1]
ntables = None # calculate the number of rows and cols
else:
connector = dataframe.connector_type
connector = dataframe._model.connector_type
if DataSourceType(datatype) != DataSourceType.MULTITABLE:
nrows = dataframe.metadata.number_of_rows
ncols = len(dataframe.metadata.columns)
Expand Down

0 comments on commit 13bfe6d

Please sign in to comment.