Skip to content

Commit 1290931

Browse files
Simplifying getting the catalog, to make linting easier
1 parent f926ffd commit 1290931

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

pandas/io/iceberg.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
from typing import (
2-
TYPE_CHECKING,
32
Any,
43
)
54

65
from pandas.compat._optional import import_optional_dependency
76

87
from pandas import DataFrame
98

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-
229

2310
def read_iceberg(
2411
table_identifier: str,
@@ -83,8 +70,11 @@ def read_iceberg(
8370
... selected_fields=("VendorID", "tpep_pickup_datetime"),
8471
... ) # doctest: +SKIP
8572
"""
86-
catalog = _get_catalog(catalog_name, catalog_properties)
73+
pyiceberg_catalog = import_optional_dependency("pyiceberg.catalog")
8774
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)
8878
table = catalog.load_table(table_identifier)
8979
if row_filter is None:
9080
row_filter = pyiceberg_expressions.AlwaysTrue()
@@ -136,8 +126,10 @@ def to_iceberg(
136126
DataFrame.to_parquet : Write a DataFrame in Parquet format.
137127
"""
138128
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)
141133
arrow_table = pa.Table.from_pandas(df)
142134
table = catalog.create_table_if_not_exists(
143135
identifier=table_identifier,

0 commit comments

Comments
 (0)