code: def train_test_split_by_time(df, timestamp, user):
      df["train_mask"] = np.ones((len(df),), dtype=np.bool_)
      df["val_mask"] = np.zeros((len(df),), dtype=np.bool_)
      df["test_mask"] = np.zeros((len(df),), dtype=np.bool_)
      df = dd.from_pandas(df, npartitions=10)
  
      def train_test_split(df):
          df = df.sort_values([timestamp])
          if df.shape[0] > 1:
              df.iloc[-1, -3] = False
              df.iloc[-1, -1] = True
          if df.shape[0] > 2:
              df.iloc[-2, -3] = False
              df.iloc[-2, -2] = True
          return df
  
      meta_df = {
          "user_id": np.int64,
          "movie_id": np.int64,
          "rating": np.int64,
          "timestamp": np.int64,
          "user_id": np.int64,
          "train_mask": bool,
          "val_mask": bool,
          "test_mask": bool,
      }
  
      df = (
          df.groupby(user, group_keys=False)
          .apply(train_test_split, meta=meta_df)
          .compute(scheduler="processes")
          .sort_index()
      )
      print(df[df[user] == df[user].unique()[0]].sort_values(timestamp))
      return (
          df["train_mask"].to_numpy().nonzero()[0],
          df["val_mask"].to_numpy().nonzero()[0],
          df["test_mask"].to_numpy().nonzero()[0],
      )
  
file_path: dgl/examples/pytorch/pinsage/data_utils.py
imports: import dask.dataframe
  import dgl
  import numpy
  import scipy.sparse
  import torch
  import tqdm
label_desc: Use image node_id 1 for calling a global function with example usage: train_test_split_by_time(df, timestamp, user) and returns: df,  df,  df, df