# Why run.scan\_history() still returns lots of NaN values

**URL:** <https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919>\
**Category:** W&B Help\
**Created:** [August 17, 2023, 11:08pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919 "2023-08-17T23:08:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xjygr08](https://avatars.discourse-cdn.com/v4/letter/x/e99b99/32.png) [@xjygr08](https://community.wandb.ai/u/xjygr08)\
**Post date:** [August 17, 2023, 11:08pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/1 "2023-08-17T23:08:48Z")

</div>

I tried to get the observations and actions I logged when running RL in gym. But I still get a lot of NaNs even I switched from run.history() to run.scan\_history() (I learned this from this link [Run.history() returns different values on almost each call - #2 by jaeheelee](https://community.wandb.ai/t/run-history-returns-different-values-on-almost-each-call/2431/2)). I thought scan\_history will return all the logged values. Am I wrong?

Here is an example

 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/f/fa7cba86fdb7de874613cef2f76289351db4f8ec.png)

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [August 22, 2023, 7:08pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/2 "2023-08-22T19:08:57Z")

</div>

Hi @xjygr08, apologies you are running into this! Could you send me a link to your workspace where you’ve stored your values as well as script snippet of how you are logging those values to wandb?

---

<div class="post-metadata">

**Author:** ![xjygr08](https://avatars.discourse-cdn.com/v4/letter/x/e99b99/32.png) [@xjygr08](https://community.wandb.ai/u/xjygr08)\
**Post date:** [August 22, 2023, 8:25pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/3 "2023-08-22T20:25:46Z")

</div>

[Weights & Biases](https://wandb.ai/xjygr08/log-obs-action/runs/qw16oje7?workspace=user-xjygr08) This is the workspace.

This is how I logged the values:

```python
import gymnasium as gym
from gymnasium.wrappers.record_episode_statistics import RecordEpisodeStatistics
import wandb

from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import DummyVecEnv

wandb.login()
config = {
    "env_name": "CartPole-v1",
    "deque_size": 1000,
}

def make_env():
    env = gym.make(config["env_name"], render_mode="rgb_array")
    env = RecordEpisodeStatistics(env, config["deque_size"])
    return env

env = DummyVecEnv([make_env])

model = PPO.load("ppo_cartpole")
run = wandb.init(
    project="log-obs-action",
)

obs = env.reset()
while True:
    action, _states = model.predict(obs)
    obs, rewards, dones, info = env.step(action)
    print(f"action={action} obs={obs} rewards={rewards} dones={dones} info={info}")
    wandb.log({"obs": obs[0][0]})
    wandb.log({"action": action[0]})
    wandb.log(info[0])

    if dones[0]:
        break
env.close()

```

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [August 28, 2023, 7:49pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/4 "2023-08-28T19:49:00Z")

</div>

Hi Jinyu,

Run.history() does return every single logged value you have. I think I found where your issue is coming form.

Inside of your code you call:  
`wandb.log({"obs": obs[0][0]}) `  
`wandb.log({"action": action[0]}) `  
`wandb.log(info[0])`

back to back. Every time your call wandb.log, is considered you taking a new step as a part of your experiment.

So in this case, for a single iteration of the `while True` loop you have, you are taking three steps at wandb and they all record different parameters. That is why:  
Your `obs` and `action` variables are logged 3 steps apart here:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/8/888cefe644b6642757bbb1787eaab4df5ebd0e6b.png)

Obs is recorded at steps 0, 3, 6, 9…  
Action is at 1,4,7,10

In order to fix this issue you can either log all of your info using the same wandb.log like this:  
`wandb.log({"obs": obs[0][0], "action": action[0], "info": info[0]})`

or by specifying steps individually inside of the wandb.log():

```auto
counter = <counter that counts your step>
wandb.log({"obs": obs[0][0]}, step = counter)
wandb.log({"action": action[0]}, step = counter)
wandb.log(info[0], step = counter)

```

---

<div class="post-metadata">

**Author:** ![xjygr08](https://avatars.discourse-cdn.com/v4/letter/x/e99b99/32.png) [@xjygr08](https://community.wandb.ai/u/xjygr08)\
**Post date:** [August 28, 2023, 10:18pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/5 "2023-08-28T22:18:34Z")

</div>

Aha, I see, this makes sense. Thank you!

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [August 28, 2023, 10:29pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/6 "2023-08-28T22:29:35Z")

</div>

No problem! I will close this ticket out, you are always welcome to write back in!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [October 27, 2023, 10:18pm UTC](https://community.wandb.ai/t/why-run-scan-history-still-returns-lots-of-nan-values/4919/7 "2023-10-27T22:18:38Z")

</div>

Closed on October 27, 2023, 10:18pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
