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

feat: allow repeat with dtype=dict #67

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Jun 11, 2024

This will be helpful to normalize model_dict, loss_dict, etc, in DeePMD-kit.

Summary by CodeRabbit

  • New Features

    • Enhanced handling of data types based on the repeat flag, supporting both lists of dicts and dicts of dicts.
    • Improved documentation generation reflecting updated data type handling.
  • Bug Fixes

    • Corrected traversal logic for values to ensure proper handling of dictionaries and lists based on the repeat flag.
  • Tests

    • Updated and added new test cases to cover changes in data type handling and traversal logic.

Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Warning

Rate limit exceeded

@njzjz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 40 minutes and 20 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 5c74333 and 8bc99d2.

Walkthrough

The changes enhance the handling of data types in the dargs library, particularly when the repeat flag is set. Now, dtype can be either a list of dicts or a dict of dicts, allowing for more flexible data structures. Adjustments were made to various functions to support this new behavior, including documentation generation and test cases to ensure proper coverage and functionality.

Changes

File(s) Change Summary
dargs/dargs.py Refined handling of dtype based on repeat flag, updated documentation generation, and traversal logic.
dargs/sphinx.py Renamed test_repeat to test_repeat_list, added test_repeat_dict argument with nested sub-fields.
tests/test_checker.py Renamed test_sub_repeat to test_sub_repeat_list, added test_sub_repeat_dict for new test cases.
tests/test_docgen.py Renamed test_sub_repeat to test_sub_repeat_list, added test_sub_repeat_dict function for complex nested structure testing.
tests/test_normalizer.py Added new dictionary sub2_dict in test_complicated function for enhanced testing.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@njzjz njzjz requested a review from iProzd June 11, 2024 21:43
@njzjz
Copy link
Member Author

njzjz commented Jun 11, 2024

@iProzd please help to see if this is useful to model_dict, etc.

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.15%. Comparing base (3167a5b) to head (8bc99d2).
Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   83.76%   84.15%   +0.39%     
==========================================
  Files           5        5              
  Lines         690      707      +17     
==========================================
+ Hits          578      595      +17     
  Misses        112      112              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range and nitpick comments (3)
dargs/sphinx.py (1)

Line range hint 61-63: Improve exception handling by linking the cause of the exception.

- raise self.error(f'Failed to import "{attr_name}" from "{module_name}".\n{sys.exc_info()[1]}')
+ raise self.error(f'Failed to import "{attr_name}" from "{module_name}".\n{sys.exc_info()[1]}') from None
dargs/dargs.py (2)

112-112: Update the comment to reflect the new functionality more clearly.

Consider enhancing the clarity of the comment by specifying what "sub fields and sub variants" entails, especially since dtype can now also be a dictionary of dictionaries.


Line range hint 360-383: Refactor the traversal logic to simplify and enhance readability.

The traversal logic for handling value based on repeat and its type (list or dict) can be refactored for better readability and maintainability. Consider using a helper method to handle the common logic.

-        if not self.repeat and isinstance(value, dict):
-            self._traverse_sub(
-                value, key_hook, value_hook, sub_hook, variant_hook, path
-            )
-        elif self.repeat and isinstance(value, list):
-            for idx, item in enumerate(value):
-                self._traverse_sub(
-                    item,
-                    key_hook,
-                    value_hook,
-                    sub_hook,
-                    variant_hook,
-                    [*path, str(idx)],
-                )
-        elif self.repeat and isinstance(value, dict):
-            for kk, item in value.items():
-                self._traverse_sub(
-                    item,
-                    key_hook,
-                    value_hook,
-                    sub_hook,
-                    variant_hook,
-                    [*path, kk],
-                )
+        self._handle_traversal(value, key_hook, value_hook, sub_hook, variant_hook, path)

Consider implementing a _handle_traversal method that encapsulates the common logic and simplifies the main traverse_value method.

dargs/dargs.py Outdated Show resolved Hide resolved
dargs/dargs.py Show resolved Hide resolved
tests/test_docgen.py Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Jinzhe Zeng <[email protected]>
@njzjz njzjz merged commit d934085 into deepmodeling:master Jun 12, 2024
7 checks passed
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