Skip to content

fix: write FLOAT and GEO values without an exponent - #2139

Closed
aplatogg wants to merge 1 commit into
PyCalendar:mainfrom
aplatogg:fix/2136-float-no-exponent
Closed

aplatogg wants to merge 1 commit into
PyCalendar:mainfrom
aplatogg:fix/2136-float-no-exponent

Conversation

@aplatogg

Copy link
Copy Markdown

What this changes

vFloat.to_ical() and vGeo.to_ical() used str() on the float, which switches to exponent notation below 1e-04 and from 1e16 on. RFC 5545 3.3.7 has no exponent, so a GEO near the equator was written as GEO:1e-05;-2e-05 and parsers that follow the grammar can reject it.

Both now format through to_ical_float(), which uses Decimal to render the shortest round-tripping decimal of the float in plain notation:

>>> from icalendar import Event, vFloat
>>> event = Event()
>>> event.add("GEO", (0.00001, -0.00002))
>>> print(event.to_ical().decode())
BEGIN:VEVENT
GEO:0.00001;-0.00002
END:VEVENT
>>> vFloat(1e16).to_ical()
b'10000000000000000'

Values that were already plain keep their spelling: vFloat(0.0) is still 0.0 and vGeo((1.2, 3.0)) is still 1.2;3.0, so the existing test_zero and test_prop_vGeo assertions hold.

Tests

  • tests/prop/test_vFloat.py: exponent cases down to 1e-7, an assertion that every written value matches the RFC grammar ^[+-]?\d+(?:\.\d+)?$, and a write/read round trip.
  • tests/prop/test_vGeo.py: the reported event, the GEO line, and a round trip.
  • news/2136.bugfix for the changelog.

pytest src/icalendar/tests gives 15956 passed and 6 failed here; all 6 fail on unmodified main too (hypothesis absent, plus the two zoneinfo tests on Windows). ruff check and ruff format --check pass for the touched files.

Closes #2136

Prepared with an AI coding assistant (Claude), as the repository asks automated contributors to identify themselves.

str() on a float switches to exponent notation below 1e-04 and from 1e16 on,
but FLOAT has no exponent in RFC 5545 3.3.7, so a GEO position near the equator
was written as GEO:1e-05;-2e-05 and stricter parsers can reject it.

Render both through to_ical_float(), which uses Decimal to write the shortest
round-tripping decimal of the float in plain notation: 1e-05 becomes 0.00001
and 1e16 becomes 10000000000000000. Values that were already plain, such as
0.0 and 42.0, keep their current spelling.

Closes PyCalendar#2136
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding. label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Mixed activity

Activity patterns show a mix of organic and automated signals.

View full analysis →

Evidence
  • Concentrated PR closures: 5 PRs closed across 2 repos in 28m (concentrated closing activity)

Last 5 PRs:

This is an automated analysis by AgentScan

@github-actions

Copy link
Copy Markdown
Contributor

One or more PR-quality checks did not pass. Review the PR Quality Checks summary in the workflow run for the failed checks and their details, then make any necessary updates.

Checklist items may remain unchecked while work is in progress. Please tick each item as you complete it.

If you used AI assistance, follow the project's Responsible AI use policy and provide the required disclosures.

@github-actions github-actions Bot added the agentscan:needs-review AgentScan flagged this item for review because it has mixed signals label Nov 17, 2026
@stevepiercy

Copy link
Copy Markdown
Member

@aplatogg there's already an open PR #2137 for issue #2136. Would you please review that PR, and provide feedback to the author?

@aplatogg

Copy link
Copy Markdown
Author

Closing this in favour of #2137. @fermsp opened that one at 02:38 for the same issue, mine at 07:0x, so a second PR here would only split review — the maintainer's comment is right.

I reviewed #2137 against its own branch: \pytest src/icalendar/tests/test_issue_2136_float_exponent.py src/icalendar/tests/prop\ gives 1298 passed, 1 skipped, and the written values match the expected output of the issue (\

@aplatogg aplatogg closed this Nov 17, 2026
@aplatogg aplatogg mentioned this pull request Nov 17, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:needs-review AgentScan flagged this item for review because it has mixed signals ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants