Skip to content

Commit

Permalink
added columns param to sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
argenisleon committed Nov 14, 2019
1 parent b5c86c3 commit 8d22b2a
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions optimus/dataframe/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import string
import unicodedata
import uuid
from ast import literal_eval
from functools import reduce
from heapq import nlargest
Expand Down Expand Up @@ -502,24 +501,27 @@ def keep(columns=None, regex=None):

@add_attr(cols)
# TODO: Create a function to sort by datatype?
def sort(order="asc"):
def sort(order="asc", columns=None):
"""
Sort dataframes columns asc or desc
:param order: 'asc' or 'desc' accepted
:param columns:
:return: Spark DataFrame
"""
_reverse = None
if order == "asc":
_reverse = False
elif order == "desc":
_reverse = True
else:
RaiseIt.value_error(order, ["asc", "desc"])
df = self
if columns is None:
_reverse = None
if order == "asc":
_reverse = False
elif order == "desc":
_reverse = True
else:
RaiseIt.value_error(order, ["asc", "desc"])

columns = self.cols.names()
columns.sort(key=lambda v: v.upper(), reverse=_reverse)
columns = df.cols.names()
columns.sort(key=lambda v: v.upper(), reverse=_reverse)

return self.select(columns)
return df.select(columns)

@add_attr(cols)
def drop(columns=None, regex=None, data_type=None):
Expand Down Expand Up @@ -2163,8 +2165,11 @@ def string_to_index(input_cols=None, output_cols=None, columns=None):
:param columns:
:return:
"""
df = self

return ml_string_to_index(df, input_cols, output_cols, columns)
df = ml_string_to_index(df, input_cols, output_cols, columns)

return df

@add_attr(cols)
def bucketizer(input_cols, splits, output_cols=None):
Expand Down

0 comments on commit 8d22b2a

Please sign in to comment.