nodes: 0, module; 1, function_definition; 2, function_name:check_valid_time_and_sort; 3, parameters; 4, block; 5, identifier:df; 6, identifier:timescol; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, identifier:days; 13, integer:5; 14, identifier:warning; 15, True; 16, comment:"""Check if the data contains reads created within the same `days` timeframe.
  
      if not, print warning and only return part of the data which is within `days` days
      Resetting the index twice to get also an "index" column for plotting the cum_yield_reads plot
      """; 17, assignment; 18, comparison_operator:timediff < days; 19, block; 20, else_clause; 21, identifier:timediff; 22, attribute; 23, identifier:timediff; 24, identifier:days; 25, return_statement; 26, block; 27, parenthesized_expression; 28, identifier:days; 29, call; 30, if_statement; 31, return_statement; 32, binary_operator:df[timescol].max() - df[timescol].min(); 33, attribute; 34, argument_list; 35, identifier:warning; 36, block; 37, call; 38, call; 39, call; 40, call; 41, identifier:reset_index; 42, expression_statement; 43, expression_statement; 44, expression_statement; 45, expression_statement; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, call; 55, call; 56, call; 57, call; 58, call; 59, line_continuation:\; 60, identifier:reset_index; 61, subscript; 62, identifier:max; 63, subscript; 64, identifier:min; 65, call; 66, identifier:reset_index; 67, keyword_argument; 68, attribute; 69, argument_list; 70, attribute; 71, argument_list; 72, attribute; 73, argument_list; 74, attribute; 75, argument_list; 76, attribute; 77, argument_list; 78, identifier:df; 79, identifier:timescol; 80, identifier:df; 81, identifier:timescol; 82, attribute; 83, argument_list; 84, identifier:drop; 85, True; 86, attribute; 87, identifier:write; 88, call; 89, attribute; 90, identifier:write; 91, string:"Likely this indicates you are combining multiple runs.\n"; 92, attribute; 93, identifier:write; 94, call; 95, identifier:logging; 96, identifier:warning; 97, call; 98, call; 99, line_continuation:\; 100, identifier:reset_index; 101, keyword_argument; 102, identifier:df; 103, identifier:sort_values; 104, identifier:timescol; 105, identifier:sys; 106, identifier:stderr; 107, attribute; 108, argument_list; 109, identifier:sys; 110, identifier:stderr; 111, identifier:sys; 112, identifier:stderr; 113, attribute; 114, argument_list; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, identifier:drop; 120, True; 121, string:"\nWarning: data generated is from more than {} days.\n"; 122, identifier:format; 123, call; 124, string:"Plots based on time are invalid and therefore truncated to first {} days.\n\n"; 125, identifier:format; 126, call; 127, string:"Time plots truncated to first {} days: invalid timespan: {} days"; 128, identifier:format; 129, call; 130, call; 131, subscript; 132, line_continuation:\; 133, identifier:sort_values; 134, identifier:timescol; 135, identifier:str; 136, argument_list; 137, identifier:str; 138, argument_list; 139, identifier:str; 140, argument_list; 141, identifier:str; 142, argument_list; 143, identifier:df; 144, comparison_operator:df[timescol] < timedelta(days=days); 145, identifier:days; 146, identifier:days; 147, identifier:days; 148, identifier:timediff; 149, subscript; 150, call; 151, identifier:df; 152, identifier:timescol; 153, identifier:timedelta; 154, argument_list; 155, keyword_argument; 156, identifier:days; 157, identifier:days
code: def check_valid_time_and_sort(df, timescol, days=5, warning=True):
      """Check if the data contains reads created within the same `days` timeframe.
  
      if not, print warning and only return part of the data which is within `days` days
      Resetting the index twice to get also an "index" column for plotting the cum_yield_reads plot
      """
      timediff = (df[timescol].max() - df[timescol].min()).days
      if timediff < days:
          return df.sort_values(timescol).reset_index(drop=True).reset_index()
      else:
          if warning:
              sys.stderr.write(
                  "\nWarning: data generated is from more than {} days.\n".format(str(days)))
              sys.stderr.write("Likely this indicates you are combining multiple runs.\n")
              sys.stderr.write(
                  "Plots based on time are invalid and therefore truncated to first {} days.\n\n"
                  .format(str(days)))
              logging.warning("Time plots truncated to first {} days: invalid timespan: {} days"
                              .format(str(days), str(timediff)))
          return df[df[timescol] < timedelta(days=days)] \
              .sort_values(timescol) \
              .reset_index(drop=True) \
              .reset_index()