microsoft/qlib · error · ValueError

Cannot find user data {}

Error message

Cannot find user data {}

What it means

Raised by UserManager.remove_user when the folder data_path/user_id does not exist. remove_user deletes the user's account directory and drops the id from the users record CSV, so it requires the directory to be present.

Source

Thrown at qlib/contrib/online/manager.py:144

        # save user
        user_path.mkdir()
        save_instance(model, self.data_path / user_id / "model_{}.pickle".format(user_id))
        save_instance(strategy, self.data_path / user_id / "strategy_{}.pickle".format(user_id))
        trade_account.save_account(self.data_path / user_id)
        user_record = pd.read_csv(self.users_file, index_col=0)
        user_record.loc[user_id] = [add_date]
        user_record.to_csv(self.users_file)

    def remove_user(self, user_id):
        """
        remove user {user_id} in current user dataset
        will delete the folder "{user_id}" in user data path
            :param
                user_id : string
        """
        user_path = self.data_path / user_id
        if not user_path.exists():
            raise ValueError("Cannot find user data {}".format(user_id))
        shutil.rmtree(user_path)
        user_record = pd.read_csv(self.users_file, index_col=0)
        user_record.drop([user_id], inplace=True)
        user_record.to_csv(self.users_file)

View on GitHub (pinned to 79633dd950)

Solutions

  1. Check existence first: if (um.data_path / user_id).exists(): um.remove_user(user_id).
  2. List the actual user folders (iterate um.data_path.iterdir()) to see valid ids before removing.
  3. If the CSV record is out of sync with disk, repair users_file manually so load/remove agree.

Example fix

# before
um.remove_user("u1")  # ValueError: Cannot find user data u1

# after
if (um.data_path / "u1").exists():
    um.remove_user("u1")
Defensive patterns

Strategy: validation

Validate before calling

if (um.data_path / user_id).exists():
    um.remove_user(user_id)

Prevention

When it happens

Trigger: Calling remove_user with a typo'd or never-created user_id; calling remove twice (the second call finds no folder); the folder was manually deleted but the id remained in users_file.

Common situations: Cleanup scripts run after someone already removed the folder by hand; retries after a partially completed removal; mismatch between the users_file CSV contents and the actual folders on disk.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/6aa4c74a60c71c52. Report an issue: GitHub.