Fix env.reset() to return (obs, info) tuple for SB3 v2.0+ compatibility#1402
Open
he-yufeng wants to merge 2 commits intoAI4Finance-Foundation:masterfrom
Open
Fix env.reset() to return (obs, info) tuple for SB3 v2.0+ compatibility#1402he-yufeng wants to merge 2 commits intoAI4Finance-Foundation:masterfrom
he-yufeng wants to merge 2 commits intoAI4Finance-Foundation:masterfrom
Conversation
…ompatibility Stable Baselines 3 v2.0+ expects env.reset() to return a (obs, info) tuple following the Gymnasium API. Four environments still returned only the observation, causing "too many values to unpack (expected 2)" when used with SB3's DummyVecEnv. Fixed environments: - env_btc_ccxt.py (BitcoinEnv) - env_multiple_crypto.py (CryptoEnv) - env_stocktrading_stoploss.py (StockTradingEnvStopLoss) - env_stocktrading_cashpenalty.py (StockTradingEnvCashpenalty) Fixes AI4Finance-Foundation#1051 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
atharvajoshi01
left a comment
There was a problem hiding this comment.
SB3 v2.0 changed the reset() API to return (obs, info) tuple. This fixes all the env classes to match. Clean and necessary for anyone using stable-baselines3 >= 2.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four environments'
reset()methods return only the observation instead of the(obs, info)tuple required by the Gymnasium API (and SB3 v2.0+), causingValueError: too many values to unpack (expected 2)when used withDummyVecEnv.Fixed Environments
env_btc_ccxt.py(BitcoinEnv)env_multiple_crypto.py(CryptoEnv)env_stocktrading_stoploss.py(StockTradingEnvStopLoss)env_stocktrading_cashpenalty.py(StockTradingEnvCashpenalty)Note:
env_stocktrading.pyandenv_stocktrading_np.pyalready return(obs, {})correctly.Change
Each fix is a single-line change:
return state→return state, {}Test plan
DummyVecEnvwrapping works with each fixed environmentFixes #1051
🤖 Generated with Claude Code