Skip to content

Commit 7d06ba2

Browse files
author
Dane Pitkin
committed
Use wrapper instead of alias for drop()
1 parent ffc2206 commit 7d06ba2

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

python/pyarrow/table.pxi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,10 +4725,9 @@ cdef class Table(_PandasConvertible):
47254725

47264726
return table
47274727

4728-
drop = drop_columns
4729-
"""
4730-
Alias of Table.drop_columns, kept for backwards compatibility.
4731-
"""
4728+
def drop(self, columns):
4729+
"""Alias of Table.drop_columns, but kept for backwards compatibility."""
4730+
return self.drop_columns(columns)
47324731

47334732
def group_by(self, keys):
47344733
"""Declare a grouping over the columns of the table.

python/pyarrow/tests/test_table.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,26 @@ def test_table_drop_columns():
10701070
table.drop_columns(['d'])
10711071

10721072

1073+
def test_table_drop():
1074+
""" verify the alias of drop_columns is working"""
1075+
a = pa.array(range(5))
1076+
b = pa.array([-10, -5, 0, 5, 10])
1077+
c = pa.array(range(5, 10))
1078+
1079+
table = pa.Table.from_arrays([a, b, c], names=('a', 'b', 'c'))
1080+
t2 = table.drop(['a', 'b'])
1081+
t3 = table.drop('a')
1082+
1083+
exp_t2 = pa.Table.from_arrays([c], names=('c',))
1084+
assert exp_t2.equals(t2)
1085+
exp_t3 = pa.Table.from_arrays([b, c], names=('b', 'c',))
1086+
assert exp_t3.equals(t3)
1087+
1088+
# -- raise KeyError if column not in Table
1089+
with pytest.raises(KeyError, match="Column 'd' not found"):
1090+
table.drop(['d'])
1091+
1092+
10731093
def test_table_remove_column():
10741094
data = [
10751095
pa.array(range(5)),

0 commit comments

Comments
 (0)