GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: TabularDataset, fix: Dataset by morgandu · Pull Request #103 · googleapis/python-aiplatform

Conversation

@morgandu

@morgandu morgandu commented Dec 2, 2020

Copy link
Copy Markdown
Contributor

List of Changes:

  • remove request_metadata field in datasets.py
  • remove request_metadata field in test_dataset.py
  • move datasets.py into dataset module
  • add tabular_datasets.py
  • add test_tabular_datasets.py

Fixes: https://b.corp.google.com/issues/174168850

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
morgandu added 2 commits December 1, 2020 17:30
@morgandu
fix: remove request_metadata field in datasets.py and test_datasets.p…
c77341b
…y, add metadata_schema_uri property in datasets.py, move datasets.py to datasets module
@morgandu
feat: add tabular_dataset.py and test_tabular_dataset.py
ad1166c
@morgandu
morgandu requested review from ivanmkc and sasha-gitg December 2, 2020 02:31
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 2, 2020
@morgandu
feat: add tabular_dataset.py and test_tabular_dataset.py
fecb309
ivanmkc
ivanmkc reviewed Dec 2, 2020
View reviewed changes
Comment thread google/cloud/aiplatform/datasets/datasets.py
@@ -83,7 +88,6 @@ def create(
gcs_source: Optional[Sequence[str]] = None,
bq_source: Optional[str] = None,
import_schema_uri: Optional[str] = None,
metadata: Sequence[Tuple[str, str]] = (),

@ivanmkc ivanmkc Dec 2, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@morgandu
fix: run linter
72cd0d6
ivanmkc
ivanmkc reviewed Dec 2, 2020
View reviewed changes
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated

@property
def import_data(self):
raise AttributeError("'TabularDataset' object has no 'import_data' method")

@ivanmkc ivanmkc Dec 2, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is the right error type.

The closest error type I see is: NotImplementedError. However, that seems to suggest that this will be implemented in the future, which is not the case here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ivanmkc ivanmkc Dec 2, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if it's better to remove the function and make it private in the superclass. Only implement it for subclasses where importing makes sense.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ivanmkc ivanmkc Dec 2, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @morgandu, I think we could later refactor Datasets.py to remove the import_data functionality from it and move it to an DatasetImportable abstract class.

Fundamentally, not ALL Datasets have import functionality (e.g. tabular doesn't).

In that proposed refactor:
TabularDataset would just subclass Dataset.
Vision, NLP and others would subclass Dataset AND DatasetImportable.

Then we wouldn't have this weird import_data function in a class that doesn't need it. And we also would have decoupled import functionality from core Dataset functionality.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sasha-gitg sasha-gitg Dec 2, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this issue should be resolved in the class hierarchy.

I think though that we still want a generic Dataset class (with name Dataset) similar to what we have now that supports all methods.

TabularDataset would just subclass Dataset.
Vision, NLP and others would subclass Dataset AND DatasetImportable.

If we go the multiple inheritance route then probably something like this:
TabularDataset would just subclass _Dataset.
Dataset, Vision, NLP and others would subclass _Dataset AND _DatasetImportable

But we can also do this without mixin:
TabularDataset would subclass _Dataset.
Dataset is a subclass of _Dataset with import and associated methods
Vision, NLP and others would subclass Dataset

To me it seems like it's cleaner without multiple inheritance because _DatasetImportable has a hard requirement on _Dataset to work.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ivanmkc ivanmkc Dec 3, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, although we might run into the diamond problem if we need to compose more functionality later on. For example, if we later have _DatasetExportable and there's a subclass that implements both _DatasetImportable and _DatasetExportable. Then we have to worry about method resolution order and such.

Just pointing that out but I'm fine either way as I believe breaking out the Import functionality is a step in the right direction in any case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that this should be changed to NotImplementedError.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

morgandu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ivanmkc
ivanmkc reviewed Dec 2, 2020
View reviewed changes
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated

return dataset_obj

@property

@ivanmkc ivanmkc Dec 2, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think the property decorator is relevant here. Property is used to create getters and setters, import_data is more of a one-off function.

reference: https://www.programiz.com/python-programming/property

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that property should be removed here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

morgandu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@morgandu
fix: resolving conflit between HEAD and ad1166c
9f33fb4
ivanmkc
ivanmkc reviewed Dec 2, 2020
View reviewed changes
Comment thread tests/unit/aiplatform/test_tabular_datasets.py
parent=_TEST_PARENT, dataset=expected_dataset
)

@pytest.mark.usefixtures("get_tabular_dataset_mock")

@ivanmkc ivanmkc Dec 2, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ivanmkc
ivanmkc approved these changes Dec 2, 2020
View reviewed changes

@ivanmkc ivanmkc left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, although I'd leave it people who were involved with the design process to give it a proper sign-off.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sasha-gitg
sasha-gitg requested changes Dec 2, 2020
View reviewed changes
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated
credentials=credentials,
)

assert self.metadata_schema_uri == schema.dataset.metadata.tabular, (

@sasha-gitg sasha-gitg Dec 2, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preference to raise an Exception instead of asserting.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ivanmkc reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py
credentials: Optional[auth_credentials.Credentials]=None,
Custom credentials to use to upload this model. Overrides
credentials set in aiplatform.init.
"""

@sasha-gitg sasha-gitg Dec 2, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a raises section.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated

@property
def import_data(self):
raise AttributeError("'TabularDataset' object has no 'import_data' method")

@sasha-gitg sasha-gitg Dec 2, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this issue should be resolved in the class hierarchy.

I think though that we still want a generic Dataset class (with name Dataset) similar to what we have now that supports all methods.

TabularDataset would just subclass Dataset.
Vision, NLP and others would subclass Dataset AND DatasetImportable.

If we go the multiple inheritance route then probably something like this:
TabularDataset would just subclass _Dataset.
Dataset, Vision, NLP and others would subclass _Dataset AND _DatasetImportable

But we can also do this without mixin:
TabularDataset would subclass _Dataset.
Dataset is a subclass of _Dataset with import and associated methods
Vision, NLP and others would subclass Dataset

To me it seems like it's cleaner without multiple inheritance because _DatasetImportable has a hard requirement on _Dataset to work.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
morgandu added 3 commits December 3, 2020 08:53
@morgandu
1. Replaced 'Dataset' class with '_Dataset' class with 'create', 'exp…
cbfce47
…ort', 'update' methods, and 'metadata_schema_uri' property which applies to all types of dataset. Removed 'import_data', '_import_data' methods. 1.1. removed 'gcs_source', 'bq_source' and replaced with optional empty 'dataset_metadata' (only used in tabular dataset creation) in 'create' method's signature. 1.2. Removed 'import_schema_uri', 'data_items_labels' from 'create' method's signature as they are used for importing data. 1.3. Removed the support for tabular dataset from 'create' method. 1.4. Removed the optional support for importing data. 2. Created a subclass 'Dataset' of '_Dataset', with supporting dataset types in '_types'. 2.1. Created 'create' method with optional support for importing data, only when both gcs_source and import_schema_uri are provided. 3. Created a subclass 'TabularDataset' of '_Dataset', with supporting dataset types in '_types'. 3.1. Created 'create' method using 'set_dataset_metadata' to validate input config when one and only one source, i.e. gcs, bq is provided. 4. Added dataset type validation for 'Dataset' and 'Tabular' Dataset. 5. Updated unit tests.
@morgandu
Revert "1. Replaced 'Dataset' class with '_Dataset' class with 'creat…
5faa803
…e', 'export', 'update' methods, and 'metadata_schema_uri' property which applies to all types of dataset. Removed 'import_data', '_import_data' methods. 1.1. removed 'gcs_source', 'bq_source' and replaced with optional empty 'dataset_metadata' (only used in tabular dataset creation) in 'create' method's signature. 1.2. Removed 'import_schema_uri', 'data_items_labels' from 'create' method's signature as they are used for importing data. 1.3. Removed the support for tabular dataset from 'create' method. 1.4. Removed the optional support for importing data. 2. Created a subclass 'Dataset' of '_Dataset', with supporting dataset types in '_types'. 2.1. Created 'create' method with optional support for importing data, only when both gcs_source and import_schema_uri are provided. 3. Created a subclass 'TabularDataset' of '_Dataset', with supporting dataset types in '_types'. 3.1. Created 'create' method using 'set_dataset_metadata' to validate input config when one and only one source, i.e. gcs, bq is provided. 4. Added dataset type validation for 'Dataset' and 'Tabular' Dataset. 5. Updated unit tests."

This reverts commit cbfce47.
@morgandu
fix: added 'Rases' section, changed Assertion to raise Exception, add…
c9a415d
…ed _type for supporting dataset type, added tabular data input config metadata constraint, added import data constraint
@morgandu
morgandu force-pushed the 174168850 branch from 5fab59c to c9a415d Compare December 3, 2020 21:24
sasha-gitg
sasha-gitg requested changes Dec 3, 2020
View reviewed changes
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated
class TabularDataset(datasets.Dataset):
"""Managed tabular dataset resource for AI Platform"""

_types = [

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this pattern. Prefer a tuple or frozenset since they are immutable.

Prefer _support_metadata_schema_uris to be less ambiguous.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@morgandu morgandu Dec 4, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed _types to _support_metadata_schema_uris with tuple

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated
credentials=credentials,
)

if self.metadata_schema_uri not in self._types:

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the base dataset class should have a method like

def _validate_metadata_schema_uri(self):
  if self._types and self.metadata_schema_uri not in self._types:
    raise Exception(
                f"{self.resource_name} can not be retrieved using "
                f"{self.__class__.__name__} class, check the dataset type"
            )

And the Dataset class can set self_types = None. And the validation can be done in the dataset class so we don't need to re-implement for every sub dataset class.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@morgandu morgandu Dec 4, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented _validate_metadata_schema_uri in Dataset class, so retrieved dataset resource can be validated against predefined _support_metadata_schema_uris in Dataset class and subclass

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated

return dataset_obj

@property

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that property should be removed here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

morgandu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread google/cloud/aiplatform/datasets/tabular_datasets.py Outdated

@property
def import_data(self):
raise AttributeError("'TabularDataset' object has no 'import_data' method")

@sasha-gitg sasha-gitg Dec 3, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that this should be changed to NotImplementedError.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

morgandu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@morgandu
fix: 1. added empty _support_metadata_schema_uris, _validate_metadata…
4098972
…_schema_uri method to Dataset 2. changed _types to tuple _support_metadata_schema_uris in TabularDataset 3. changed import_data method to raise NotImplementedError
@morgandu
morgandu requested a review from sasha-gitg December 9, 2020 23:20
@morgandu morgandu mentioned this pull request Dec 30, 2020
feat: specialized dataset classes, fix: datasets refactor #153
Merged
@morgandu

morgandu commented Jan 7, 2021

Copy link
Copy Markdown
Contributor Author

changes are reflected in #153

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@morgandu morgandu closed this Jan 7, 2021
@morgandu
morgandu deleted the 174168850 branch March 17, 2021 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sasha-gitg sasha-gitg Awaiting requested review from sasha-gitg
1 more reviewer
@ivanmkc ivanmkc ivanmkc approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@morgandu @ivanmkc @sasha-gitg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.