Skip to content

fix : ZstdError handling for Python <3.14 & >=3.14 compatibility#767

Merged
bhimrazy merged 1 commit into
Lightning-AI:mainfrom
bhimrazy:fix/zstd-error-handling
Dec 8, 2025
Merged

fix : ZstdError handling for Python <3.14 & >=3.14 compatibility#767
bhimrazy merged 1 commit into
Lightning-AI:mainfrom
bhimrazy:fix/zstd-error-handling

Conversation

@bhimrazy

@bhimrazy bhimrazy commented Dec 4, 2025

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes #766

Changes

  • Import ZstdError from compression.zstd for Python >= 3.14
  • Import zstd.Error from zstd for older Python versions
  • Add test to verify ZstdError is properly caught for corrupted data

PR review

Anyone in the community is free to review the PR once the tests have passed.

Did you have fun?

Make sure you had fun coding ��

- Import ZstdError from compression.zstd for Python >= 3.14
- Import ZstdError from zstd for older Python versions
- Add test to verify ZstdError is properly caught for corrupted data

Fixes Lightning-AI#766
Copilot AI review requested due to automatic review settings December 4, 2025 19:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes ZstdError import handling to ensure compatibility across Python versions, specifically addressing the breaking change where Python 3.14+ includes zstd as a built-in module under compression.zstd while older versions use the third-party zstd package. The fix properly handles the exception class name differences (ZstdError in Python 3.14+ vs Error in older versions) to prevent import errors and ensure corrupted data is properly caught.

Key Changes:

  • Updated exception handling in _load_index_file and _save_index_file to import and use the correct ZstdError class based on Python version
  • Added test coverage to verify ZstdError is properly caught when decompressing corrupted data

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/litdata/raw/indexer.py Added version-specific imports for ZstdError and updated exception handlers to use the imported exception class instead of zstd.ZstdError
tests/raw/test_indexer.py Added test to verify corrupted zstd data raises ZstdError and is properly handled by the indexer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/raw/test_indexer.py
Comment thread src/litdata/raw/indexer.py
@codecov

codecov Bot commented Dec 4, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80%. Comparing base (0770595) to head (afeb063).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #767   +/-   ##
===================================
  Coverage    80%    80%           
===================================
  Files        52     52           
  Lines      7343   7347    +4     
===================================
+ Hits       5883   5890    +7     
+ Misses     1460   1457    -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bhimrazy bhimrazy changed the title fix : ZstdError import handling for Python <3.14 & >=3.14 compatibility fix : ZstdError handling for Python <3.14 & >=3.14 compatibility Dec 4, 2025
@bhimrazy bhimrazy merged commit 825586b into Lightning-AI:main Dec 8, 2025
43 checks passed
@bhimrazy bhimrazy deleted the fix/zstd-error-handling branch December 8, 2025 17:03
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.

zstd.ZstdError missing for Python < 3.14 fallback import

4 participants