nodes: 0, module; 1, function_definition; 2, function_name:reshuffle; 3, parameters; 4, block; 5, identifier:expr; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:by; 15, None; 16, identifier:sort; 17, None; 18, identifier:ascending; 19, True; 20, comment:"""
      Reshuffle data.
  
      :param expr:
      :param by: the sequence or scalar to shuffle by. RandomScalar as default
      :param sort: the sequence or scalar to sort.
      :param ascending: True if ascending else False
      :return: collection
      """; 21, assignment; 22, assignment; 23, identifier:sort; 24, block; 25, call; 26, identifier:by; 27, boolean_operator; 28, identifier:grouped; 29, call; 30, expression_statement; 31, identifier:ReshuffledCollectionExpr; 32, argument_list; 33, identifier:by; 34, call; 35, attribute; 36, argument_list; 37, assignment; 38, keyword_argument; 39, keyword_argument; 40, identifier:RandomScalar; 41, argument_list; 42, identifier:expr; 43, identifier:groupby; 44, identifier:by; 45, identifier:grouped; 46, call; 47, identifier:_input; 48, identifier:grouped; 49, identifier:_schema; 50, attribute; 51, attribute; 52, argument_list; 53, identifier:expr; 54, identifier:_schema; 55, identifier:grouped; 56, identifier:sort_values; 57, identifier:sort; 58, keyword_argument; 59, identifier:ascending; 60, identifier:ascending
code: def reshuffle(expr, by=None, sort=None, ascending=True):
      """
      Reshuffle data.
  
      :param expr:
      :param by: the sequence or scalar to shuffle by. RandomScalar as default
      :param sort: the sequence or scalar to sort.
      :param ascending: True if ascending else False
      :return: collection
      """
  
      by = by or RandomScalar()
  
      grouped = expr.groupby(by)
      if sort:
          grouped = grouped.sort_values(sort, ascending=ascending)
  
      return ReshuffledCollectionExpr(_input=grouped, _schema=expr._schema)