Separate the rating datafram into train and test sets.

  Filters out users with less than two distinct timestamps. Creates train set
  and test set. The test set contains all the last interactions of users with
  more than two distinct timestamps.

  Args:
    ratings_df: pandas dataframe with columns 'userId', 'movieId', 'rating',
      'timestamp'.

  Returns:
    tuple of dataframes (filtered_ratings, train_ratings, test_ratings).

def _preprocess_movie_lens(ratings_df):
  """Separate the rating datafram into train and test sets.

  Filters out users with less than two distinct timestamps. Creates train set
  and test set. The test set contains all the last interactions of users with
  more than two distinct timestamps.

  Args:
    ratings_df: pandas dataframe with columns 'userId', 'movieId', 'rating',
      'timestamp'.

  Returns:
    tuple of dataframes (filtered_ratings, train_ratings, test_ratings).
  """
  ratings_df["data"] = 1.0
  num_timestamps = ratings_df[["userId", "timestamp"]].groupby(
      "userId").nunique()
  last_user_timestamp = ratings_df[["userId", "timestamp"]].groupby(
      "userId").max()

  ratings_df["numberOfTimestamps"] = ratings_df["userId"].apply(
      lambda x: num_timestamps["timestamp"][x])
  ratings_df["lastTimestamp"] = ratings_df["userId"].apply(
      lambda x: last_user_timestamp["timestamp"][x])

  ratings_df = ratings_df[ratings_df["numberOfTimestamps"] > 2]

  ratings_df = _create_row_col_indices(ratings_df)

  train_ratings_df = ratings_df[
      ratings_df["timestamp"] < ratings_df["lastTimestamp"]]
  test_ratings_df = ratings_df[
      ratings_df["timestamp"] == ratings_df["lastTimestamp"]]

  return ratings_df, train_ratings_df, test_ratings_df