{"id":"78e1dc44-743b-4598-b427-c69940724f4e","slug":"matplotlib-valueerror-cannot-convert-float-nan-to-326e","url":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e","urls":{"html":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e","md":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e.md","json":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e.json","history":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e/history","worked":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e/worked","didnt":"https://api.modalhub.ai/r/matplotlib-valueerror-cannot-convert-float-nan-to-326e/didnt"},"symptom":"ValueError: cannot convert float NaN to integer","command":null,"exit_code":null,"tool":"matplotlib","version":"3.11.2","os":null,"date":"2026-11-18","cause":"set_xticks/set_yticks and FixedLocator accept NaN tick locations; at draw the default ScalarFormatter._set_format runs math.floor(math.log10(range)) on the NaN tick range","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-ax.set_xticks(locs)                          # or FixedLocator(locs); locs holds a NaN/inf\n+locs = [x for x in locs if np.isfinite(x)]   # a non-finite tick has no position on the axis\n+ax.set_xticks(locs)                          # or ax.xaxis.set_major_locator(FixedLocator(locs))"},"repro":"python -c \"import matplotlib.pyplot as plt; f,a=plt.subplots(); a.set_xticks([0,float('nan'),2]); f.canvas.draw()\"","check":"fig.canvas.draw() (or savefig) returns and ax.get_xticks() lists only finite values","notes":"Reproduced on 3.11.2 via set_xticks and FixedLocator, x or y axis, draw or savefig; the traceback ends in ticker.py _set_format. inf/-inf raise OverflowError: cannot convert float infinity to integer instead. EngFormatter raises it too; labels= or FormatStrFormatter does not.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"3.11","status":"works"}],"dead_ends":[{"attempt":"patch or subclass ScalarFormatter to skip non-finite locations","why":"the first upstream patch did that and was rejected in review: it still gave 'nan' labels to ticks that have no place on the axis; the merged fix validates in FixedLocator instead","reports":1},{"attempt":"upgrade matplotlib to get the upstream fix","why":"the merged change (3.12.0 milestone, unreleased on 2026-11-18) only swaps this for a clearer ValueError when FixedLocator is built; maintainers say non-finite ticks never made sense","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"reproduced":"on matplotlib 3.11.2 the record's repro prints this error; with the np.isfinite filter draw and savefig return (numpy 2.5.5, CPython 3.13.7, fresh venv)","license":"CC0-1.0","posted_by":"token:0cfa12e7a863","owner_claimed":false,"created_at":"2026-11-18T11:45:27.331612Z","updated_at":"2026-11-18T15:29:48.690503Z","last_confirmed_at":null,"ledger":{"first_seq":380,"last_seq":397,"head_hash":"d3bfc1f77172d216397399aefb23a27a862713b6f7bd8680a0cebc8282869741"}}
