Skip to content

Commit b925ad7

Browse files
committed
Fix whitespace and documentation errors
1 parent b07f00b commit b925ad7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

python/datafusion/dataframe.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,28 +409,29 @@ def select(self, *exprs: Expr | str) -> DataFrame:
409409
def drop(self, *columns: str) -> DataFrame:
410410
"""Drop arbitrary amount of columns.
411411
412-
Column names are case-sensitive and do not require double quotes like
413-
other operations such as `select`. Leading and trailing double quotes
412+
Column names are case-sensitive and do not require double quotes like
413+
other operations such as `select`. Leading and trailing double quotes
414414
are allowed and will be automatically stripped if present.
415415
416416
Args:
417-
columns: Column names to drop from the dataframe. Both 'column_name'
418-
and '"column_name"' are accepted.
417+
columns: Column names to drop from the dataframe. Both ``column_name``
418+
and ``"column_name"`` are accepted.
419419
420420
Returns:
421421
DataFrame with those columns removed in the projection.
422-
423-
Example Usage:
422+
423+
Example Usage::
424+
424425
df.drop('ID_For_Students') # Works
425426
df.drop('"ID_For_Students"') # Also works (quotes stripped)
426427
"""
427428
normalized_columns = []
428429
for col in columns:
429430
if col.startswith('"') and col.endswith('"'):
430-
normalized_columns.append(col.strip('"')) # Removes quotes from both sides of col
431+
normalized_columns.append(col.strip('"')) # Strip double quotes
431432
else:
432433
normalized_columns.append(col)
433-
434+
434435
return DataFrame(self.df.drop(*normalized_columns))
435436

436437
def filter(self, *predicates: Expr) -> DataFrame:

python/tests/test_dataframe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,17 @@ def test_select(df):
216216
assert result.column(0) == pa.array([4, 5, 6])
217217
assert result.column(1) == pa.array([1, 2, 3])
218218

219+
219220
def test_drop_quoted_columns():
220221
ctx = SessionContext()
221222
batch = pa.RecordBatch.from_arrays([pa.array([1, 2, 3])], names=["ID_For_Students"])
222223
df = ctx.create_dataframe([[batch]])
223-
224+
224225
# Both should work
225226
assert df.drop('"ID_For_Students"').schema().names == []
226-
assert df.drop('ID_For_Students').schema().names == []
227+
assert df.drop("ID_For_Students").schema().names == []
228+
227229

228-
229230
def test_select_mixed_expr_string(df):
230231
df = df.select(column("b"), "a")
231232

0 commit comments

Comments
 (0)