Skip to content

Write FLOAT values without an exponent - #2137

Open
fermsp wants to merge 1 commit into
PyCalendar:mainfrom
fermsp:fix-2136-float-exponent
Open

fermsp wants to merge 1 commit into
PyCalendar:mainfrom
fermsp:fix-2136-float-exponent

Conversation

@fermsp

@fermsp fermsp commented Nov 17, 2026

Copy link
Copy Markdown

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
@@ -0,0 +1 @@
Fixed :class:~icalendar.prop.float.vFloat and :class:~icalendar.prop.geo.vGeo writing very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of :rfc:5545#section-3.3.7 does not allow an exponent. @fermsp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your quick response and contribution.

Let's polish up the reStructuredText in this news fragment so that it links. You can check how it renders in the pull request preview under the CI check for docs/readthedocs.org:icalendar under Reference > Change log.

Suggested change
Fixed :class:~icalendar.prop.float.vFloat and :class:~icalendar.prop.geo.vGeo writing very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of :rfc:5545#section-3.3.7 does not allow an exponent. @fermsp
Fixed :class:`~icalendar.prop.float.vFloat` and :class:`~icalendar.prop.geo.vGeo` to write very small and very large numbers without an exponent, instead of, for example, ``GEO:1e-05;-2e-05``. The FLOAT value type of :rfc:`5545#section-3.3.7` does not allow an exponent. @fermsp

Otherwise this looks good to me, and I'll pass it over to a maintainer for final review.

@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.

This branch has not been deployed

No deployments
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