yt-project/yt

Incorrect parameter sanitation to np.logspace

yohad opened this issue · 2 comments

Bug report

Bug summary

In function b2t in frontends/art/io.py, the call to np.logspace passes the third argument without validating it is an integer.

Code for reproduction
When loading my database I get n=100.0 when trying to load ("stars", "particle_creation_time")

Version Information

  • Operating System: Linux Cluster (not sure which OS)
  • Python Version: 3.12.2
  • yt version: 4.3.1
  • Other Libraries (if applicable): numpy=1.26.4

installed yt from conda-forge

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

Thanks for reporting !
Indeed, np.logspace's third argument doesn't accept float values, which means the default value we use in the following function is broken

yt/yt/frontends/art/io.py

Lines 630 to 638 in e9ba8ac

def b2t(tb, n=1e2, logger=None, **kwargs):
tb = np.array(tb)
if isinstance(tb, float):
return a2t(b2a(tb))
if tb.shape == ():
return a2t(b2a(tb))
if len(tb) < n:
n = len(tb)
tbs = -1.0 * np.logspace(np.log10(-tb.min()), np.log10(-tb.max()), n)

There are a couple ways we can address this, but there's precedent in just converting to int on the fly in this situation in the very same module:

spacings = np.logspace(np.log10(xmin), np.log10(xmax), num=int(n))

So I'll open a PR to do just that.