Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type Alias for datasets pattern and refactoring #2770

Closed
wants to merge 4 commits into from

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Jul 5, 2023

NOTE: Kedro datasets are moving from kedro.extras.datasets to a separate kedro-datasets package in
kedro-plugins repository. Any changes to the dataset implementations
should be done by opening a pull request in that repository.

Description

Development notes

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam mentioned this pull request Jul 5, 2023
9 tasks
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam changed the title Add TypeAlias for datasets pattern and refactoring Add Type Alias for datasets pattern and refactoring Jul 6, 2023
@@ -30,6 +30,8 @@
CREDENTIALS_KEY = "credentials"
WORDS_REGEX_PATTERN = re.compile(r"\W+")

Patterns = dict[str, dict[str, Any]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this an overkill? I found that we don't do this in kedro other than datasets which use DI_ and DO_ for data input/output. In this case I do think it has value as it helps a lot to read the code especially when we have a lot of dict of dict flowing around everywhere, I think this put some context.

@astrojuanlu WDYT about using type alias?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is a good use of a type alias! Not sure the lowercase dict will work for them (but if they do, fantastic - I sometimes get lost with Python typing)

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
kedro/io/data_catalog.py Outdated Show resolved Hide resolved
@@ -186,8 +188,8 @@ def __init__( # pylint: disable=too-many-arguments
self.layers = layers
# Keep a record of all patterns in the catalog.
# {dataset pattern name : dataset pattern body}
self._dataset_patterns = dict(dataset_patterns or {})
self._load_versions = dict(load_versions or {})
self._dataset_patterns = dataset_patterns or {}
Copy link
Member

Choose a reason for hiding this comment

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

This means that dataset_patterns don't get converted to dict anymore right? Hope there's not any weird corner case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dataset_patterns is already a dict[str, dict[str, Any]], no?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I meant to say that I don't know how this function is used - if it's internal and we know that the inputs are dictionaries already, then all is fine 👍🏽

Co-authored-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
@noklam noklam marked this pull request as ready for review July 6, 2023 12:43
@noklam noklam requested a review from merelcht as a code owner July 6, 2023 12:43
@noklam
Copy link
Contributor Author

noklam commented Jul 6, 2023

Closing it in favor of #2776

@noklam noklam closed this Jul 6, 2023
@astrojuanlu astrojuanlu deleted the fix/type branch July 6, 2023 15:17
@astrojuanlu astrojuanlu restored the fix/type branch July 6, 2023 15:18
@merelcht merelcht deleted the fix/type branch October 6, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants