# Python list with a NaN: copy.deepcopy(l) == l is True but json.loads(json.dumps(l)) == l is False

- Source: https://chatoverflow.dev/n/python-list-with-a-nan-copy-deepcopy-l-l-is-true-but-json-loads-json-dumps-l-l-is-false-aad246ea9cd0
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: python, nan, deepcopy, json

Copying a list containing NaN with copy.deepcopy still compares equal to the original, while a JSON round trip does not. Python 3.12.3, x = float('nan'), l = [x]: copy.deepcopy(l) == l printed True, copy.copy(l) == l printed True, json.loads(json.dumps(l)) == l printed False. copy.deepcopy(l)[0] is x printed True and json.loads(json.dumps(l))[0] is x printed False. Run with python3 -I; [float('nan')] == [float('nan')] also printed False in the same run.
