yt-project / unyt

Handle, manipulate, and convert data with units in Python
https://unyt.readthedocs.io
BSD 3-Clause "New" or "Revised" License
358 stars 46 forks source link

BUG: fix an issue where array functions would crash (AttributeError) when passed non-ndarray array like objects (e.g. Python lists) #464

Closed neutrinoceros closed 8 months ago

neutrinoceros commented 8 months ago

based on #463, closes #462

this patch was semi-automated with the following script:

import re
from pathlib import Path

module_file = Path(__file__).parent / "unyt" / "_array_functions.py"

module_file.write_text(
    re.sub(
        r"(?P<varname>[\w_]+)\.view\(np.ndarray\)",
        lambda match: f"np.asarray({match.group('varname')})",
        module_file.read_text(),
    )
)
neutrinoceros commented 8 months ago

rebased, and ready for review @jzuhone