Skip to content

Commit

Permalink
depr(api): deprecate Table.relabel in favor of Table.rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Aug 30, 2023
1 parent e856438 commit ea4d559
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,13 @@ def select(

projection = select

@util.deprecated(
as_of="7.0",
instead=(
"use `Table.rename` instead (if passing a mapping, note the meaning "
"of keys and values are swapped in Table.rename)."
),
)
def relabel(
self,
substitutions: Mapping[str, str]
Expand Down
14 changes: 9 additions & 5 deletions ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,26 @@ def test_relabel():
table = api.table({"x": "int32", "y": "string", "z": "double"})

# Using a mapping
res = table.relabel({"x": "x_1", "y": "y_1"}).schema()
with pytest.warns(FutureWarning, match="Table.rename"):
res = table.relabel({"x": "x_1", "y": "y_1"}).schema()
sol = sch.schema({"x_1": "int32", "y_1": "string", "z": "double"})
assert_equal(res, sol)

# Using a function
res = table.relabel(lambda x: None if x == "z" else f"{x}_1").schema()
with pytest.warns(FutureWarning, match="Table.rename"):
res = table.relabel(lambda x: None if x == "z" else f"{x}_1").schema()
assert_equal(res, sol)

# Using a format string
res = table.relabel("_{name}_")
sol = table.relabel({"x": "_x_", "y": "_y_", "z": "_z_"})
with pytest.warns(FutureWarning, match="Table.rename"):
res = table.relabel("_{name}_")
sol = table.relabel({"x": "_x_", "y": "_y_", "z": "_z_"})
assert_equal(res, sol)

# Mapping with unknown columns errors
with pytest.raises(com.IbisTypeError, match="'missing' is not found in table"):
table.relabel({"missing": "oops"})
with pytest.warns(FutureWarning, match="Table.rename"):
table.relabel({"missing": "oops"})


def test_rename():
Expand Down

0 comments on commit ea4d559

Please sign in to comment.