|
1 | 1 | from typing import ( |
2 | | - TYPE_CHECKING, |
3 | 2 | Any, |
4 | 3 | ) |
5 | 4 |
|
6 | 5 | from pandas.compat._optional import import_optional_dependency |
7 | 6 |
|
8 | 7 | from pandas import DataFrame |
9 | 8 |
|
10 | | -if TYPE_CHECKING: |
11 | | - from pyiceberg.catalog import Catalog |
12 | | - |
13 | | - |
14 | | -def _get_catalog( |
15 | | - catalog_name: str | None, catalog_properties: dict[str, Any] | None |
16 | | -) -> "Catalog": |
17 | | - pyiceberg_catalog = import_optional_dependency("pyiceberg.catalog") |
18 | | - if catalog_properties is None: |
19 | | - catalog_properties = {} |
20 | | - return pyiceberg_catalog.load_catalog(catalog_name, **catalog_properties) |
21 | | - |
22 | 9 |
|
23 | 10 | def read_iceberg( |
24 | 11 | table_identifier: str, |
@@ -83,8 +70,11 @@ def read_iceberg( |
83 | 70 | ... selected_fields=("VendorID", "tpep_pickup_datetime"), |
84 | 71 | ... ) # doctest: +SKIP |
85 | 72 | """ |
86 | | - catalog = _get_catalog(catalog_name, catalog_properties) |
| 73 | + pyiceberg_catalog = import_optional_dependency("pyiceberg.catalog") |
87 | 74 | pyiceberg_expressions = import_optional_dependency("pyiceberg.expressions") |
| 75 | + if catalog_properties is None: |
| 76 | + catalog_properties = {} |
| 77 | + catalog = pyiceberg_catalog.load_catalog(catalog_name, **catalog_properties) |
88 | 78 | table = catalog.load_table(table_identifier) |
89 | 79 | if row_filter is None: |
90 | 80 | row_filter = pyiceberg_expressions.AlwaysTrue() |
@@ -136,8 +126,10 @@ def to_iceberg( |
136 | 126 | DataFrame.to_parquet : Write a DataFrame in Parquet format. |
137 | 127 | """ |
138 | 128 | pa = import_optional_dependency("pyarrow") |
139 | | - |
140 | | - catalog = _get_catalog(catalog_name, catalog_properties) |
| 129 | + pyiceberg_catalog = import_optional_dependency("pyiceberg.catalog") |
| 130 | + if catalog_properties is None: |
| 131 | + catalog_properties = {} |
| 132 | + catalog = pyiceberg_catalog.load_catalog(catalog_name, **catalog_properties) |
141 | 133 | arrow_table = pa.Table.from_pandas(df) |
142 | 134 | table = catalog.create_table_if_not_exists( |
143 | 135 | identifier=table_identifier, |
|
0 commit comments