-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): get current dataset statistics
- Loading branch information
Showing
3 changed files
with
205 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from radicalbit_platform_sdk.apis import ModelCurrentDataset | ||
from radicalbit_platform_sdk.models import CurrentFileUpload, ModelType, JobStatus | ||
from radicalbit_platform_sdk.errors import ClientError | ||
import responses | ||
import unittest | ||
import uuid | ||
|
||
|
||
class ModelCurrentDatasetTest(unittest.TestCase): | ||
@responses.activate | ||
def test_statistics_ok(self): | ||
base_url = "http://api:9000" | ||
model_id = uuid.uuid4() | ||
import_uuid = uuid.uuid4() | ||
n_variables = 10 | ||
n_observations = 1000 | ||
missing_cells = 10 | ||
missing_cells_perc = 1 | ||
duplicate_rows = 10 | ||
duplicate_rows_perc = 1 | ||
numeric = 3 | ||
categorical = 6 | ||
datetime = 1 | ||
model_reference_dataset = ModelCurrentDataset( | ||
base_url, | ||
model_id, | ||
ModelType.BINARY, | ||
CurrentFileUpload( | ||
uuid=import_uuid, | ||
path="s3://bucket/file.csv", | ||
date="2014", | ||
correlation_id_column="column", | ||
status=JobStatus.IMPORTING, | ||
), | ||
) | ||
|
||
responses.add( | ||
**{ | ||
"method": responses.GET, | ||
"url": f"{base_url}/api/models/{str(model_id)}/current/{str(import_uuid)}/statistics", | ||
"status": 200, | ||
"body": f"""{{ | ||
"datetime": "something_not_used", | ||
"jobStatus": "SUCCEEDED", | ||
"statistics": {{ | ||
"nVariables": {n_variables}, | ||
"nObservations": {n_observations}, | ||
"missingCells": {missing_cells}, | ||
"missingCellsPerc": {missing_cells_perc}, | ||
"duplicateRows": {duplicate_rows}, | ||
"duplicateRowsPerc": {duplicate_rows_perc}, | ||
"numeric": {numeric}, | ||
"categorical": {categorical}, | ||
"datetime": {datetime} | ||
}} | ||
}}""", | ||
} | ||
) | ||
|
||
stats = model_reference_dataset.statistics() | ||
|
||
assert stats.n_variables == n_variables | ||
assert stats.n_observations == n_observations | ||
assert stats.missing_cells == missing_cells | ||
assert stats.missing_cells_perc == missing_cells_perc | ||
assert stats.duplicate_rows == duplicate_rows | ||
assert stats.duplicate_rows_perc == duplicate_rows_perc | ||
assert stats.numeric == numeric | ||
assert stats.categorical == categorical | ||
assert stats.datetime == datetime | ||
assert model_reference_dataset.status() == JobStatus.SUCCEEDED | ||
|
||
@responses.activate | ||
def test_statistics_validation_error(self): | ||
base_url = "http://api:9000" | ||
model_id = uuid.uuid4() | ||
import_uuid = uuid.uuid4() | ||
model_reference_dataset = ModelCurrentDataset( | ||
base_url, | ||
model_id, | ||
ModelType.BINARY, | ||
CurrentFileUpload( | ||
uuid=import_uuid, | ||
path="s3://bucket/file.csv", | ||
date="2014", | ||
correlation_id_column="column", | ||
status=JobStatus.IMPORTING, | ||
), | ||
) | ||
|
||
responses.add( | ||
**{ | ||
"method": responses.GET, | ||
"url": f"{base_url}/api/models/{str(model_id)}/current/{str(import_uuid)}/statistics", | ||
"status": 200, | ||
"body": '{"statistics": "wrong"}', | ||
} | ||
) | ||
|
||
with self.assertRaises(ClientError): | ||
model_reference_dataset.statistics() | ||
|
||
@responses.activate | ||
def test_statistics_key_error(self): | ||
base_url = "http://api:9000" | ||
model_id = uuid.uuid4() | ||
import_uuid = uuid.uuid4() | ||
model_reference_dataset = ModelCurrentDataset( | ||
base_url, | ||
model_id, | ||
ModelType.BINARY, | ||
CurrentFileUpload( | ||
uuid=import_uuid, | ||
path="s3://bucket/file.csv", | ||
date="2014", | ||
correlation_id_column="column", | ||
status=JobStatus.IMPORTING, | ||
), | ||
) | ||
|
||
responses.add( | ||
**{ | ||
"method": responses.GET, | ||
"url": f"{base_url}/api/models/{str(model_id)}/current/{str(import_uuid)}/statistics", | ||
"status": 200, | ||
"body": '{"wrong": "json"}', | ||
} | ||
) | ||
|
||
with self.assertRaises(ClientError): | ||
model_reference_dataset.statistics() |