Skip to content

Write FLOAT values without an exponent - #2137

Merged
stevepiercy merged 3 commits into
PyCalendar:mainfrom
fermsp:fix-2136-float-exponent
Nov 19, 2026
Merged

stevepiercy merged 3 commits into
PyCalendar:mainfrom
fermsp:fix-2136-float-exponent

Conversation

@fermsp

@fermsp fermsp commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Description

vFloat.to_ical() and vGeo.to_ical() wrote very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of RFC 5545 has none. These values are now written with all their digits. Other values, xCal and jCal are unchanged.

Checklist

  • I added a change log entry, following the instructions in all subsections under Change log requirements.
  • I followed icalendar's Artificial intelligence policy and disclosed my Responsible AI use in my commit messages, if applicable.
  • I added or updated tests, if applicable.
  • I ran and ensured all tests pass locally by following Run tests.
  • I added or edited documentation as necessary, both as docstrings to be rendered in the API documentation and narrative documentation, following the Style guide.

vFloat.to_ical() and vGeo.to_ical() wrote very small and very large
numbers as 1e-05, which RFC 5545 section 3.3.7 does not allow.

Closes PyCalendar#2136
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @fermsp! A maintainer will review it shortly.

@github-actions

Copy link
Copy Markdown
Contributor

Insufficient data

Not enough activity yet to make a reliable assessment.

View full analysis →

This is an automated analysis by AgentScan

Comment thread news/2136.bugfix Resolved
angatha
angatha previously approved these changes Nov 17, 2026

@aplatogg aplatogg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed against your branch locally (PYTHONPATH pointed at your src/, pytest src/icalendar/tests/test_issue_2136_float_exponent.py src/icalendar/tests/prop): 1298 passed, 1 skipped. The approach is right and the output matches what #2136 asks for. Three points, in priority order.

1. news/2136.bugfix needs backticks around the roles. As written, the entry renders them as literal text instead of links:

Fixed :class:~icalendar.prop.float.vFloat writing values.

For Fixed :class:~... I rendered that through docutils and got the string back unchanged. Every other fragment in news/ writes :class:`~icalendar.prop.float.vFloat` and :rfc:`5545#section-3.3.7` with backticks, e.g. news/1084.bugfix. Both roles in that sentence need them.

2. inf/nan still write an invalid FLOAT, unchanged by this PR. vFloat(float("inf")).to_ical() is b'inf', which the grammar does not allow, because _float_to_ical only rewrites a repr that contains e. from_ical rejects those values, so nothing new is broken here, and I would keep the fix out of this PR. A math.isfinite() guard before formatting is where it would go if you want it later.

3. Optional, test placement. tests/prop/test_vFloat.py holds the vFloat tests and the vGeo assertions live in tests/prop/test_unit.py. A dedicated test_issue_2136_* file works, but folding the four cases into those two files may be what a maintainer asks for. No functional difference.

For the record, what I checked on your branch beyond the test suite: 0.1 -> b'0.1', so the shortest representation survives instead of expanding to full precision; 0.0 -> b'0.0'; -0.0 -> b'-0.0'; 1e16 -> b'10000000000000000'; 5e-324 writes 326 digits and parses back to the same float; vGeo((0.0, -0.0)) -> '0.0;-0.0'.

I had an independent PR for this (#2139) and closed it, so this is the only one open for #2136.

@stevepiercy

Copy link
Copy Markdown
Member

@fermsp do you need anything from us? It'd be good to finish this up and get it merged. Please let us know. Thank you!

@fermsp

fermsp commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@stevepiercy sorry for the delay, nothing needed from you! This is my first contribution to an open source project, so I'm still learning the workflow. I applied your suggestion to the news fragment. Sorry also for the noise with the force push: I clicked "Update branch" by mistake and then reverted it, which dismissed @angatha's approval. The code is unchanged since that approval. The "Check built packages" job failed after 7 seconds on the previous push, before building anything, and make test-dist passes locally.

@fermsp
fermsp requested a review from stevepiercy November 19, 2026 00:21
@stevepiercy

Copy link
Copy Markdown
Member

@fermsp no worries. It's OK to update your branch against main by clicking the "Update branch" button, as our review process requires that pull requests by updated before they're merged. This is a good practice, ensuring CI passes and that there are no merge conflicts.

@stevepiercy
stevepiercy enabled auto-merge (squash) November 19, 2026 01:17
@stevepiercy

Copy link
Copy Markdown
Member

@fermsp I approved and enabled automerge. Thank you for your contribution to icalendar!

@stevepiercy
stevepiercy merged commit 60cdd8a into PyCalendar:main Nov 19, 2026
52 checks passed
@fermsp
fermsp deleted the fix-2136-float-exponent branch November 19, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] FLOAT and GEO values are written with an exponent

5 participants