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

Make EDTF parser available as undate formatter; handle 5+ digit years #89

Merged
merged 7 commits into from
Nov 8, 2024

Conversation

rlskoeser
Copy link
Member

@rlskoeser rlskoeser commented Aug 16, 2024

This adds glue between undate and the existing EDTF parsing by adding a date formatter class. The parse method simply uses the parser and transformer; the to string method uses custom logic because I couldn't figure out an elegant way to leverage the parsing code (there's a reconstruct method but the tree is pretty complicated).

I also added support for parsing and formatting 5+ digit years now that we support it (this is based on the numpy code in #84 ).

@rlskoeser rlskoeser marked this pull request as draft August 16, 2024 21:54
@rlskoeser rlskoeser marked this pull request as ready for review August 29, 2024 22:21
@rlskoeser
Copy link
Member Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link

@kypso-io kypso-io bot left a comment

Choose a reason for hiding this comment

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

📋 Review Summary

  • Number of files reviewed: 10
  • Number of comments: 5
  • Number of suggestions: 4

📚 File changes

File path File changes
src/undate/date.py Updated comments and rearranged precision constants in the DatePrecision class.
src/undate/dateformat/edtf/init.py Added import statement for EDTFDateFormat from the formatter module.
src/undate/dateformat/edtf/formatter.py Added EDTF parser as undate formatter and handled 5+ digit years.
src/undate/dateformat/edtf/transformer.py Updated the year_fivedigitsplus method to accept items instead of token and modified the logic to handle 5+ digit years.
src/undate/dateformat/iso8601.py Removed duplicate import statement for typing.
src/undate/undate.py Added validation TODO, fixed comparison logic for precision, and refactored date part retrieval methods.
tests/test_date.py Added tests for DatePrecision comparisons and modified test structure for Date initialization.
tests/test_dateformat/edtf/test_edtf_transformer.py Updated test cases to include support for 5+ digit years.
tests/test_dateformat/test_edtf.py Added tests for parsing and formatting 5+ digit years in the EDTFDateFormat.
tests/test_undate.py Added tests for year, month, and day properties of the Undate class.

src/undate/dateformat/edtf/formatter.py Show resolved Hide resolved
src/undate/dateformat/edtf/formatter.py Show resolved Hide resolved
src/undate/dateformat/edtf/formatter.py Show resolved Hide resolved
Comment on lines 262 to 263
# is precision sufficient for comparing partially known dates?
self.precision > other.precision,
self.precision < other.precision,
Copy link

Choose a reason for hiding this comment

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

bug_fix
The comparison logic for precision should be corrected. The original line checks if self.precision is greater than other.precision, which may lead to incorrect behavior. It should be less than instead, as indicated by the change in the diff.

tests/test_dateformat/test_edtf.py Show resolved Hide resolved
Copy link
Collaborator

@ColeDCrawford ColeDCrawford left a comment

Choose a reason for hiding this comment

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

Think this will need to be updated with the #84 changes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Made the same comment over in the numpy PR #84, but wanted to flag here too:

One potential issue with ordering it this way is that it's going to be harder to extend. I guess we could do DECADE = 0? My understanding is that we can't get precise than DAY (since we're not recording times) but there are potentially future cases where we might want to be less precise than YEAR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having trouble testing this locally. Recreated venv after testing the numpy branch, but I'm getting ModuleNotFoundErrors: Hint: make sure your test modules/packages have valid Python names.. Guessing this will resolve if #84 is rebased in here?

@rlskoeser
Copy link
Member Author

Think this will need to be updated with the #84 changes?

It is branched off from that but will probably need to be updated, they may have diverged by now. I'll update this one after the big numpy refactor is finally merged into develop.

Copy link

@kypso-io kypso-io bot left a comment

Choose a reason for hiding this comment

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

📋 Review Summary

  • Number of files reviewed: 10
  • Number of comments: 3
  • Number of suggestions: 2

📚 File changes

File path File changes
src/undate/date.py Updated comments for clarity and corrected the order of precision constants.
src/undate/dateformat/edtf/init.py Added import statement for EDTFDateFormat from the formatter module.
src/undate/dateformat/edtf/formatter.py Added EDTF parser as undate formatter and support for 5+ digit years.
src/undate/dateformat/edtf/transformer.py Changed the parameter of year_fivedigitsplus from token to items and updated the implementation to handle 5+ digit years.
src/undate/dateformat/iso8601.py Removed duplicate import statement for typing.
src/undate/undate.py Added validation for expected string lengths, modified comparison logic for date precision, and refactored date part retrieval methods.
tests/test_date.py Added tests for DatePrecision comparisons and modified test method names.
tests/test_dateformat/edtf/test_edtf_transformer.py Updated test cases and comments related to level 1 functionality and year support.
tests/test_dateformat/test_edtf.py Added tests for parsing and formatting 5+ digit years in the EDTFDateFormat.
tests/test_undate.py Added tests for properties accessing parts of the date, including year, month, and day.
Ignored comments

src/undate/date.py

  • refactor_suggestion: The comments regarding the precision of the date units should be consistent and clear. The previous comment indicated that year precision is greater than month precision, which is misleading. It would be better to clarify the relationship between the different precisions without ambiguity.

comparison, e.g. year is LESS precise than month

numbers should be set to allow logical greater than / less than

e.g. YEAR < MONTH < DAY

  • refactor_suggestion: The order of the precision constants should be corrected to reflect their actual precision levels. The YEAR constant should be set to 1, MONTH to 2, and DAY to 3, which is already correctly represented in the new lines. The old lines should be removed to avoid confusion.

YEAR = 1

MONTH = 2

DAY = 3

src/undate/dateformat/edtf/init.py

  • refactor_suggestion: Consider adding an __all__ variable to explicitly declare the public interface of this module. This can improve clarity about what is intended to be part of the public API.

src/undate/dateformat/edtf/formatter.py

  • refactor_suggestion: The to_string method contains several TODO comments regarding handling uncertain or approximate dates. It would be better to implement this functionality or at least provide a clear mechanism for handling these cases to avoid leaving the method incomplete.
            # Implement handling for uncertain / approximate dates here
            # For example, you could check for specific flags or conditions

src/undate/dateformat/edtf/transformer.py

  • refactor_suggestion: The method year_fivedigitsplus has been changed to accept items instead of token, which is a good improvement for consistency. However, the comment about the limitation of 4-digit years should be removed since the functionality now supports 5+ digit years. Additionally, consider renaming the method to reflect its capability to handle 5+ digit years more clearly.

src/undate/dateformat/iso8601.py

  • refactor_suggestion: The import statement for Dict, List, and Union is duplicated. It should be removed from the second occurrence to maintain clean code and avoid redundancy.

src/undate/undate.py

  • refactor_suggestion: The TODO comment suggests adding validation for string lengths, which is important for ensuring that the input values conform to expected formats. Consider implementing this validation to prevent potential issues with unexpected string lengths during parsing.

  • refactor_suggestion: The methods for retrieving year, month, and day could be refactored to reduce redundancy. Consider creating a single method that handles the formatting and retrieval of date parts to streamline the code and improve maintainability.

tests/test_date.py

  • refactor_suggestion: The test methods should follow a consistent naming convention to improve clarity. Consider renaming test_init_year_month_day to test_init_year_month to accurately reflect the parameters being tested.

  • refactor_suggestion: The test_comparison method could be better organized by grouping related assertions together. This will enhance readability and maintainability of the test cases.

tests/test_dateformat/edtf/test_edtf_transformer.py

  • refactor_suggestion: The comments regarding the limitations of the undate functionality have been modified. It is important to ensure that any comments accurately reflect the current capabilities of the code. If undate now supports years beyond 9999, the comment should be updated to reflect that. Otherwise, it may mislead future developers about the functionality.

tests/test_undate.py

  • refactor_suggestion: The assertions for the month property on line 149 should use == instead of is for string comparison. The is operator checks for identity, not equality, which can lead to unexpected results when comparing strings.
    assert Undate(2023, "XX").month == "XX"

  • refactor_suggestion: The assertions for the day property on line 163 should use == instead of is for string comparison. The is operator checks for identity, not equality, which can lead to unexpected results when comparing strings.
    assert Undate(2023, 1, "XX").day == "XX"

src/undate/dateformat/edtf/formatter.py Show resolved Hide resolved
src/undate/undate.py Outdated Show resolved Hide resolved
tests/test_dateformat/test_edtf.py Show resolved Hide resolved
Base automatically changed from experiment/numpy-datetime64 to develop November 7, 2024 22:29
@rlskoeser rlskoeser merged commit 6ca21f7 into develop Nov 8, 2024
11 checks passed
@rlskoeser rlskoeser deleted the feature/edtf-formatter branch November 8, 2024 20:50
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