-
Notifications
You must be signed in to change notification settings - Fork 15
Out of range dates #200
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
Open
Philip-robinson
wants to merge
5
commits into
dimastbk:master
Choose a base branch
from
cactus-bm:patch/out-of-range-dates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Out of range dates #200
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
88b62bf
Return out-of-range dates as ISO 8601 strings instead of crashing
Philip-robinson d265bea
tests: add out-of-range date fixtures and tests
Philip-robinson 6763903
tests: add requirements.txt to install local build for testing
Philip-robinson 20ab146
tests: regenerate ODS fixture with odfpy to fix whitespace parse error
Philip-robinson f0a5be4
Tests added
Philip-robinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,3 +139,4 @@ dmypy.json | |
|
|
||
| # IDE stuff | ||
| .vscode | ||
| .idea | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -e . | ||
| pytest~=8.0 | ||
| pandas[excel]~=2.0 | ||
| numpy~=1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """ | ||
| Tests verifying that date/datetime cells whose year falls outside Python's | ||
| datetime range are returned as ISO 8601 strings rather than raising an error. | ||
|
|
||
| Boundary: year <= 1000 or year > 9999 → str; otherwise → date/datetime. | ||
|
|
||
| Fixtures: | ||
| out_of_range_dates.xlsx — two sheets with future date serials (year 10000) | ||
| out_of_range_dates.ods — two sheets with past ISO dates (year 500) | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from python_calamine import CalamineWorkbook | ||
|
|
||
| PATH = Path(__file__).parent / "data" | ||
| XLSX = PATH / "out_of_range_dates.xlsx" | ||
| ODS = PATH / "out_of_range_dates.ods" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # xlsx — future dates (serial 2958466+ maps to year 10000) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_xlsx_future_date_returns_string(): | ||
| sheet = CalamineWorkbook.from_object(XLSX).get_sheet_by_name("future_date") | ||
| rows = sheet.to_python() | ||
| cell = rows[0][0] | ||
| assert isinstance(cell, str), f"expected str for out-of-range date, got {type(cell)}: {cell!r}" | ||
|
|
||
|
|
||
| def test_xlsx_future_date_string_is_iso_format(): | ||
| sheet = CalamineWorkbook.from_object(XLSX).get_sheet_by_name("future_date") | ||
| cell = sheet.to_python()[0][0] | ||
| # chrono formats with %Y-%m-%d; year 10000 gives "10000-01-01" or similar | ||
| parts = cell.split("-") | ||
| assert len(parts) == 3, f"expected YYYY-MM-DD, got {cell!r}" | ||
| assert int(parts[0]) > 9999, f"expected year > 9999, got {cell!r}" | ||
|
|
||
|
|
||
| def test_xlsx_future_datetime_returns_string(): | ||
| sheet = CalamineWorkbook.from_object(XLSX).get_sheet_by_name("future_datetime") | ||
| rows = sheet.to_python() | ||
| cell = rows[0][0] | ||
| assert isinstance(cell, str), f"expected str for out-of-range datetime, got {type(cell)}: {cell!r}" | ||
|
|
||
|
|
||
| def test_xlsx_future_datetime_string_contains_time_component(): | ||
| sheet = CalamineWorkbook.from_object(XLSX).get_sheet_by_name("future_datetime") | ||
| cell = sheet.to_python()[0][0] | ||
| assert "T" in cell, f"expected ISO datetime with 'T' separator, got {cell!r}" | ||
| date_part = cell.split("T")[0] | ||
| year = int(date_part.split("-")[0]) | ||
| assert year > 9999, f"expected year > 9999 in {cell!r}" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # ODS — past dates (ISO value "0500-06-15", year 500) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_ods_past_date_returns_string(): | ||
| sheet = CalamineWorkbook.from_object(ODS).get_sheet_by_name("past_date") | ||
| rows = sheet.to_python() | ||
| cell = rows[0][0] | ||
| assert isinstance(cell, str), f"expected str for out-of-range date, got {type(cell)}: {cell!r}" | ||
|
|
||
|
|
||
| def test_ods_past_date_string_is_iso_format(): | ||
| sheet = CalamineWorkbook.from_object(ODS).get_sheet_by_name("past_date") | ||
| cell = sheet.to_python()[0][0] | ||
| parts = cell.split("-") | ||
| assert len(parts) == 3, f"expected YYYY-MM-DD, got {cell!r}" | ||
| assert int(parts[0]) <= 1000, f"expected year <= 1000, got {cell!r}" | ||
|
|
||
|
|
||
| def test_ods_past_datetime_returns_string(): | ||
| sheet = CalamineWorkbook.from_object(ODS).get_sheet_by_name("past_datetime") | ||
| rows = sheet.to_python() | ||
| cell = rows[0][0] | ||
| assert isinstance(cell, str), f"expected str for out-of-range datetime, got {type(cell)}: {cell!r}" | ||
|
|
||
|
|
||
| def test_ods_past_datetime_string_contains_time_component(): | ||
| sheet = CalamineWorkbook.from_object(ODS).get_sheet_by_name("past_datetime") | ||
| cell = sheet.to_python()[0][0] | ||
| assert "T" in cell, f"expected ISO datetime with 'T' separator, got {cell!r}" | ||
| date_part = cell.split("T")[0] | ||
| year = int(date_part.split("-")[0]) | ||
| assert year <= 1000, f"expected year <= 1000 in {cell!r}" |
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.
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.
🧩 Analysis chain
🌐 Web query:
What are datetime.MINYEAR and datetime.MAXYEAR in Python 3's datetime module?💡 Result:
In Python's datetime module, MINYEAR and MAXYEAR are constants that define the supported range for year values in date and datetime objects [1][2]. - datetime.MINYEAR is 1 [1][2]. - datetime.MAXYEAR is 9999 [1][2]. Any year value provided to a date or datetime constructor or method must fall within the range [MINYEAR, MAXYEAR] inclusive [1][2]. Attempting to use a year outside this range will typically raise a ValueError [3].
Citations:
🏁 Script executed:
Repository: dimastbk/python-calamine
Length of output: 997
Change year bounds check to match Python's
datetime.MINYEAR(1).Lines 33 and 41 incorrectly reject years in the range [1, 1000] using
v.year() <= 1000, which downgrades valid Python dates to string representation. Python'sdatetimemodule allows years [1, 9999] inclusive. Change the condition tov.year() < 1to align withdatetime.MINYEAR.Proposed fix
🤖 Prompt for AI Agents