Skip to content

Commit fd4fcf0

Browse files
committed
Deprecate singular external table location
AI Disclosure: This code was written in part by an AI agent.:
1 parent f3faa73 commit fd4fcf0

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

crates/core/src/expr/create_external_table.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ impl PyCreateExternalTable {
118118
Ok(self.create.name.to_string())
119119
}
120120

121-
pub fn location(&self) -> String {
122-
self.create.locations.first().cloned().unwrap_or_default()
123-
}
124-
125121
pub fn locations(&self) -> Vec<String> {
126122
self.create.locations.clone()
127123
}

python/datafusion/expr.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
from collections.abc import Callable, Iterable, Sequence
5050
from typing import TYPE_CHECKING, Any, ClassVar
5151

52+
try:
53+
from warnings import deprecated # Python 3.13+
54+
except ImportError:
55+
from typing_extensions import deprecated # Python 3.12
56+
5257
import pyarrow as pa
5358

5459
from ._internal import expr as expr_internal
@@ -90,6 +95,25 @@
9095
CreateCatalog = expr_internal.CreateCatalog
9196
CreateCatalogSchema = expr_internal.CreateCatalogSchema
9297
CreateExternalTable = expr_internal.CreateExternalTable
98+
99+
100+
@deprecated("CreateExternalTable.location() is deprecated; use locations() instead.")
101+
def _create_external_table_location(self: Any) -> str:
102+
"""Return the first external table location.
103+
104+
Examples:
105+
>>> class Command:
106+
... def locations(self) -> list[str]:
107+
... return ["data.csv"]
108+
>>> _create_external_table_location(Command())
109+
'data.csv'
110+
"""
111+
locations = self.locations()
112+
return locations[0] if locations else ""
113+
114+
115+
CreateExternalTable.location = _create_external_table_location
116+
93117
CreateFunction = expr_internal.CreateFunction
94118
CreateFunctionBody = expr_internal.CreateFunctionBody
95119
CreateIndex = expr_internal.CreateIndex

python/tests/test_expr.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from concurrent.futures import ThreadPoolExecutor
2020
from datetime import date, datetime, time, timezone
2121
from decimal import Decimal
22+
from unittest.mock import MagicMock
2223

2324
import arro3.core
2425
import nanoarrow
@@ -39,6 +40,7 @@
3940
BinaryExpr,
4041
Column,
4142
CopyTo,
43+
CreateExternalTable,
4244
CreateIndex,
4345
DescribeTable,
4446
DmlStatement,
@@ -68,6 +70,17 @@ def test_ctx():
6870
return ctx
6971

7072

73+
def test_create_external_table_location_is_deprecated():
74+
"""The singular location accessor delegates to locations()."""
75+
command = MagicMock()
76+
command.locations.return_value = ["first.csv", "second.csv"]
77+
78+
with pytest.warns(DeprecationWarning, match=r"location\(\).+deprecated"):
79+
location = CreateExternalTable.location(command)
80+
81+
assert location == "first.csv"
82+
83+
7184
def test_projection(test_ctx):
7285
df = test_ctx.sql("select c1, 123, c1 < 123 from test")
7386
plan = df.logical_plan()

0 commit comments

Comments
 (0)