Skip to content

Conversation

@andersbogsnes
Copy link
Contributor

Added a NotInstalledException check when pyiceberg_core is imported for pyarrow_transforms This will raise a helpful error message when endusers try to use methods that depend on pyiceberg_core but haven't installed the optional dependency

Closes #1987

Rationale for this change

If an enduser hasn't installed the pyiceberg_core optional dependency, using pyarrow transforms will crash with an unhelpful error. This PR gives the enduser a nicer error message that informs them to install the optional dependency

Are these changes tested?

Yes, a test was added to verify the behaviour

Are there any user-facing changes?

Added a NotInstalledException check when pyiceberg_core is imported for pyarrow_transforms
This will raise a helpful error message when endusers try to use methods that depend on pyiceberg_core
but haven't installed the optional dependency
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding this. I added a few nit comments

btw we added pyiceberg_core as a dep of pyarrow extra

pyarrow = ["pyarrow", "pyiceberg-core"]

TRUNCATE_PARSER = ParseNumberFromBrackets(TRUNCATE)


def _try_import(module_name: str, extras_name: str | None = None) -> types.ModuleType:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: feels like we should move this somewhere else, other than in transforms.py but i cant find a suitable place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I couldn't immediately find a spot for it - I saw some other uses of an import check in tables which could potentially also use the function.

Could potentially go in utils/optional_deps.py or something similar? Given the number of optional dependencies, I'm sure there are other areas that could use a helper like this

Pandas has it under compat/_optional.py for reference: https://github.com/pandas-dev/pandas/blob/main/pandas/compat/_optional.py

Copy link
Contributor

Choose a reason for hiding this comment

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

i think its fine to leave this here now :)

@kevinjqliu
Copy link
Contributor

looks like linter errored, could you run make lint locally?

pyiceberg/transforms.py:112: error: X | Y syntax for unions requires Python 3.10  [syntax]
Installing missing stub packages:

we still support python 3.9 which dont have the | syntax

extras_name: str | None

->

extras_name: Optional[str]

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM!

@kevinjqliu kevinjqliu merged commit e9c0253 into apache:main Jul 18, 2025
10 checks passed
@kevinjqliu
Copy link
Contributor

thanks for the pr @andersbogsnes

@andersbogsnes andersbogsnes deleted the add_import_check_for_pyiceberg_core branch July 18, 2025 21:40
@andersbogsnes
Copy link
Contributor Author

Thanks for the review! Hope to do some more now that I'm set up 😄

gabeiglio pushed a commit to Netflix/iceberg-python that referenced this pull request Aug 13, 2025
Added a NotInstalledException check when pyiceberg_core is imported for
pyarrow_transforms This will raise a helpful error message when endusers
try to use methods that depend on pyiceberg_core but haven't installed
the optional dependency

<!--
Thanks for opening a pull request!
-->

Closes apache#1987 

# Rationale for this change
If an enduser hasn't installed the `pyiceberg_core` optional dependency,
using pyarrow transforms will crash with an unhelpful error. This PR
gives the enduser a nicer error message that informs them to install the
optional dependency

# Are these changes tested?
Yes, a test was added to verify the behaviour

# Are there any user-facing changes?

<!-- In the case of user-facing changes, please add the changelog label.
-->

---------

Co-authored-by: Anders Bogsnes <andersbognes@gmail.com>
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.

Dependency on pyiceberg_core while still marked as Optional

2 participants