[RLlib] Minor fix on json encoding during worker sampling #20134
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.
Why are these changes needed?
This PR fixes a minor bug on json encoding during worker sampling (specifically when output_writer write batch).
Currently, when output_writer write batch, it first transforms data into json file.
If data contains type that is not json serializable, error occurs while dumping.
In rllib, this usually happens in custom env with custom infos.
Luckly, similar issues have been reported before (#2243) and SafeFallbackEncoder has been implemented.
This PR contributes in two way
Regarding the improvement of SafeFallbackEncoder, order of nan checking and np.ndarray type check has been changed.
This is because return of np.isnan(ndarray object) is not boolean but array of boolean.
if np.isnan(np.array([1,1])): -> throws error
Therefore, ndarray type check has to be checked before checking nan
Also, type check of np.bool_ is added.
Using implemented SafeFallbackEncoder,
Related issue number
"Resolves #5785 "
Checks
scripts/format.sh
to lint the changes in this PR.