Skip to content

Commit f85fc00

Browse files
committed
Small doc overhauls
1 parent d24040c commit f85fc00

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

dataikuapi/dss/dataset.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from . import recipe
1212

1313
class DSSDatasetListItem(DSSTaggableObjectListItem):
14-
"""An item in a list of datasets. Do not instantiate this class"""
14+
"""An item in a list of datasets. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_datasets`"""
1515
def __init__(self, client, data):
1616
super(DSSDatasetListItem, self).__init__(data)
1717
self.client = client
@@ -51,7 +51,7 @@ def get_column(self, column):
5151

5252
class DSSDataset(object):
5353
"""
54-
A dataset on the DSS instance
54+
A dataset on the DSS instance. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.get_dataset`
5555
"""
5656
def __init__(self, client, project_key, dataset_name):
5757
self.client = client
@@ -105,9 +105,9 @@ def get_settings(self):
105105
"""
106106
data = self.client._perform_json("GET", "/projects/%s/datasets/%s" % (self.project_key, self.dataset_name))
107107

108-
if data["type"] in self.__class__.FS_TYPES:
108+
if data["type"] in self.__class__._FS_TYPES:
109109
return FSLikeDatasetSettings(self, data)
110-
elif data["type"] in self.__class__.SQL_TYPES:
110+
elif data["type"] in self.__class__._SQL_TYPES:
111111
return SQLDatasetSettings(self, data)
112112
else:
113113
return DSSDatasetSettings(self, data)
@@ -539,33 +539,41 @@ def get_object_discussions(self):
539539
# Test / Autofill
540540
########################################################
541541

542-
FS_TYPES = ["Filesystem", "UploadedFiles", "FilesInFolder",
542+
_FS_TYPES = ["Filesystem", "UploadedFiles", "FilesInFolder",
543543
"HDFS", "S3", "Azure", "GCS", "FTP", "SCP", "SFTP"]
544544
# HTTP is FSLike but not FS
545545

546-
SQL_TYPES = ["JDBC", "PostgreSQL", "MySQL", "Vertica", "Snowflake", "Redshift",
546+
_SQL_TYPES = ["JDBC", "PostgreSQL", "MySQL", "Vertica", "Snowflake", "Redshift",
547547
"Greenplum", "Teradata", "Oracle", "SQLServer", "SAPHANA", "Netezza",
548548
"BigQuery", "Athena", "hiveserver2"]
549549

550550
def test_and_detect(self, infer_storage_types=False):
551+
"""Used internally by autodetect_settings. It is not usually required to call this method"""
551552
settings = self.get_settings()
552553

553-
if settings.type in self.__class__.FS_TYPES:
554+
if settings.type in self.__class__._FS_TYPES:
554555
future_resp = self.client._perform_json("POST",
555556
"/projects/%s/datasets/%s/actions/testAndDetectSettings/fsLike"% (self.project_key, self.dataset_name),
556557
body = {"detectPossibleFormats" : True, "inferStorageTypes" : infer_storage_types })
557558

558559
return DSSFuture(self.client, future_resp.get('jobId', None), future_resp)
559-
elif settings.type in self.__class__.SQL_TYPES:
560+
elif settings.type in self.__class__._SQL_TYPES:
560561
return self.client._perform_json("POST",
561562
"/projects/%s/datasets/%s/actions/testAndDetectSettings/externalSQL"% (self.project_key, self.dataset_name))
562563
else:
563564
raise ValueError("don't know how to test/detect on dataset type:%s" % settings.type)
564565

565566
def autodetect_settings(self, infer_storage_types=False):
567+
"""
568+
Detects appropriate settings for this dataset using Dataiku detection engine
569+
570+
Returns new suggested settings that you can :meth:`DSSDatasetSettings.save`
571+
572+
:rtype: :class:`DSSDatasetSettings` or a subclass
573+
"""
566574
settings = self.get_settings()
567575

568-
if settings.type in self.__class__.FS_TYPES:
576+
if settings.type in self.__class__._FS_TYPES:
569577
future = self.test_and_detect(infer_storage_types)
570578
result = future.wait_for_result()
571579

@@ -578,7 +586,7 @@ def autodetect_settings(self, infer_storage_types=False):
578586

579587
return settings
580588

581-
elif settings.type in self.__class__.SQL_TYPES:
589+
elif settings.type in self.__class__._SQL_TYPES:
582590
result = self.test_and_detect()
583591

584592
if not "schemaDetection" in result:
@@ -591,6 +599,7 @@ def autodetect_settings(self, infer_storage_types=False):
591599
raise ValueError("don't know how to test/detect on dataset type:%s" % settings.type)
592600

593601
def get_as_core_dataset(self):
602+
"""Returns the :class:`dataiku.Dataset` object corresponding to this dataset"""
594603
import dataiku
595604
return dataiku.Dataset("%s.%s" % (self.project_key, self.dataset_name))
596605

@@ -626,6 +635,13 @@ def new_recipe(self, type, recipe_name=None):
626635
return builder
627636

628637
class DSSDatasetSettings(DSSTaggableObjectSettings):
638+
"""
639+
Base settings class for a DSS dataset.
640+
Do not instantiate this class directly, use :meth:`DSSDataset.get_settings`
641+
642+
Use :meth:`save` to save your changes
643+
"""
644+
629645
def __init__(self, dataset, settings):
630646
super(DSSDatasetSettings, self).__init__(settings)
631647
self.dataset = dataset
@@ -643,6 +659,10 @@ def get_raw_params(self):
643659
def type(self):
644660
return self.settings["type"]
645661

662+
@property
663+
def schema_columns(self):
664+
return self.settings["schema"]["columns"]
665+
646666
def remove_partitioning(self):
647667
self.settings["partitioning"] = {"dimensions" : []}
648668

@@ -661,6 +681,13 @@ def save(self):
661681
body=self.settings)
662682

663683
class FSLikeDatasetSettings(DSSDatasetSettings):
684+
"""
685+
Settings for a files-based dataset. This class inherits from :class:`DSSDatasetSettings`.
686+
Do not instantiate this class directly, use :meth:`DSSDataset.get_settings`
687+
688+
Use :meth:`save` to save your changes
689+
"""
690+
664691
def __init__(self, dataset, settings):
665692
super(FSLikeDatasetSettings, self).__init__(dataset, settings)
666693

@@ -692,6 +719,12 @@ def set_partitioning_file_pattern(self, pattern):
692719
self.settings["partitioning"]["filePathPattern"] = pattern
693720

694721
class SQLDatasetSettings(DSSDatasetSettings):
722+
"""
723+
Settings for a SQL dataset. This class inherits from :class:`DSSDatasetSettings`.
724+
Do not instantiate this class directly, use :meth:`DSSDataset.get_settings`
725+
726+
Use :meth:`save` to save your changes
727+
"""
695728
def __init__(self, dataset, settings):
696729
super(SQLDatasetSettings, self).__init__(dataset, settings)
697730

0 commit comments

Comments
 (0)