kevinjqliu commented on code in PR #2221:
URL: https://github.com/apache/iceberg-python/pull/2221#discussion_r2216893476
##########
pyiceberg/transforms.py:
##########
@@ -382,8 +396,7 @@ def __repr__(self) -> str:
return f"BucketTransform(num_buckets={self._num_buckets})"
def pyarrow_transform(self, source: IcebergType) -> "Callable[[pa.Array],
pa.Array]":
- from pyiceberg_core import transform as pyiceberg_core_transform
-
+ pyiceberg_core_transform = _try_import("pyiceberg_core",
extras_name="pyiceberg_core").transform
Review Comment:
nit: the extra is named `pyiceberg-core` but i think `pyiceberg_core` still
works in this case
https://github.com/apache/iceberg-python/blob/ad8263b1be048c8cb67d40efe70f494a4f1cb374/pyproject.toml#L318
##########
pyiceberg/transforms.py:
##########
@@ -106,6 +109,17 @@
TRUNCATE_PARSER = ParseNumberFromBrackets(TRUNCATE)
+def _try_import(module_name: str, extras_name: str | None = None) ->
types.ModuleType:
+ try:
+ return importlib.import_module(module_name)
+ except ImportError:
+ if extras_name:
+ msg = f"{module_name} needs to be installed. `pip install
pyiceberg[{extras_name}]`"
Review Comment:
nit: pip expects quoted strings for extras
```
pip install "pyiceberg[pyiceberg_core]"
```
```suggestion
msg = f"{module_name} needs to be installed. pip install
\"pyiceberg[{extras_name}]\""
```
##########
pyiceberg/transforms.py:
##########
@@ -106,6 +109,17 @@
TRUNCATE_PARSER = ParseNumberFromBrackets(TRUNCATE)
+def _try_import(module_name: str, extras_name: str | None = None) ->
types.ModuleType:
Review Comment:
nit: feels like we should move this somewhere else, other than in
`transforms.py` but i cant find a suitable place
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]