Skip to content

Releases: rstudio/reticulate

reticulate 1.30

13 Jun 20:27
Compare
Choose a tag to compare
  • Fix compilation error on R 3.5.
  • Update minimum R version dependency to 3.5.

reticulate 1.29

05 Jun 23:47
Compare
Choose a tag to compare

Exceptions and Errors:

  • R error information (call, message, other attributes) is now
    preserved as an R error condition traverses the R <-> Python boundary.

  • Python Exceptions now inherit from error and condition, and can be
    passed directly to base::stop() to signal an error in R and raise an
    exception in Python.

  • Raised Python Exceptions are now used directly to signal an R error.
    For example, in the following code, e is now an object that
    inherits from python.builtin.Exception as well as error and condition:

    e <- tryCatch(py_func_that_raises_exception(),
                  error = function(e) e)

    Use base::conditionCall() and base::conditionMessage() to access
    the original R call and error message.

  • py_last_error() return object contains r_call, r_trace and/or
    r_class if the Python Exception was raised by an R function called
    from Python.

  • The hint to run reticulate::py_last_error() after an exception
    is now clickable in the RStudio IDE.

  • Filepaths to Python files in the print output from py_last_error() are
    now clickable links in the RStudio IDE.

  • Python exceptions encountered in repl_python() are now printed with the
    full Python traceback by default. In the RStudio IDE, filepaths in the tracebacks
    are rendered as clickable links. (#1240)

Language:

  • Converted Python callables gain support for dynamic dots from the rlang package.
    New features:

    • splicing (unpacking) arguments: fn(!!!kwargs)
    • dynamic names: nm <- "key"; fn("{nm}" := value)
    • trailing commas ignored (matching Python syntax): fn(a, ) identical to fn(a)
  • New Ops group generics for Python objects:
    +, -, *, /, ^, %%, %/%, &, |, !, %*%.
    Methods for all the Ops group generics are now defined for Python objects. (#1187, #1363)
    E.g., this now works:

    np <- reticulate::import("numpy", convert = FALSE)
    x <- np$array(1:5)
    y <- np$array(6:10)
    x + y
  • Fixed two issues with R comparison operator methods
    (==, !=, <, <=, >=, >):

    • The operators no longer error on Python objects that define "rich comparison"
      Python methods that don't return a single bool. (e.g., numpy arrays).
    • The operators now respect the 'convert' value of the supplied Python objects.
      Note, this may be a breaking change as, e.g, ==, may now no long return
      an R scalar logical if one of the Python object being compared was created
      with convert = FALSE. Wrap the result of the comparison with py_bool() to
      restore the previous behavior.
      (#1187, #1363)
  • R functions wrapping Python callables now have formals matching
    those of the Python callable signature, enabling better
    autocompletion in more contexts (#1361).

  • new nameOfClass() S3 method for Python types, enabling usage:
    base::inherits(x, <python-type-object>) (requires R >= 4.3.0)

  • py_run_file() and source_python() now prepend the script directory to
    the Python module search path, sys.path, while the requested script is executing.
    This allows the Python scripts to resolve imports of modules defined in the
    script directory, matching the behavior of python <script> at the command line.
    (#1347)

knitr:

  • The knitr engine now suppresses warnings from Python code if
    warning=FALSE is set in the chunk options. (quarto-dev/quarto#125, #1358)

  • Fixed issue where reticulate's knitr engine would attach comments in a
    code chunk to the wrong code chunk (requires Python>=3.8) (#1223).

  • The knitr Python engine now respects the strip.white option (#1273).

  • Fixed issue where the knitr engine would show an additional plot from a chunk
    if the user called matplotlib.pyplot.show() (#1380, #1383)

Misc:

  • py_to_r() now succeeds when converting subtypes of the built-in
    types (e.g. list, dict, str). (#1352, #1348, #1226, #1354, #1366)

  • New pillar::type_sum() method now exported for Python objects. That ensures
    the full object class name is printing in R tracebacks and tibbles
    containing Python objects.

  • py_load_object() gains a convert argument. If convert = FALSE,
    the returned Python object will not be converted to an R object.

  • Fixed error r_to_py() with Pandas>=2.0 and R data.frames with a
    factor column containing levels with NA.

  • r_to_py() now succeeds for many additional types of R objects.
    Objects that reticulate doesn't know how to convert are presented to
    the Python runtime as a pycapsule (an opaque pointer to the underlying
    R object). Previously this would error.
    This allows for R code to pass R objects that cannot be safely
    converted to Python through the Python runtime to other R code.
    (e.g, to an R function called by Python code). (#1304)

  • reticulate gains the ability to bind to micromamba Python installations
    (#1378, #1176, #1382, #1379, thanks to Zia Khan, @zia1138)

  • Default Python version used by install_miniconda() and friends
    is now 3.9 (was 3.8).

reticulate 1.28

27 Jan 21:20
Compare
Choose a tag to compare
  • Fixed issue where source_python() (and likely many other entrypoints)
    would error if reticulate was built with Rcpp 1.0.10. Exception and
    error handling has been updated to accommodate usage of R_ProtectUnwind().
    (#1328, #1329).

  • Fixed issue where reticulate failed to discover Python 3.11 on Windows. (#1325)

  • Fixed issue where reticulate would error by attempting to bind to
    a cygwin/msys2 installation of Python on Windows (#1325).

reticulate 1.27

07 Jan 19:37
Compare
Choose a tag to compare

reticulate 1.26

31 Aug 20:38
Compare
Choose a tag to compare
  • Fixed issue where reticulate failed to bind to python2. (#1241, #1229)

  • A warning is now issued when reticulate binds to python2 that python2
    support will be removed in an upcoming reticulate release.

  • py_id() now returns a character string instead of an R integer (#1216).

  • Fixed an issue where py_to_r() would not convert elements of a
    dictionary (#1221).

  • Fixed an issue where setting RETICULATE_PYTHON or RETICULATE_PYTHON_FALLBACK
    on Windows to the pyenv-win python.bat shim would result in an error (#1263).

  • Fixed an issue where datetime.datetime objects with a tzinfo attribute
    was not getting converted to R correctly (#1266).

  • Fixed an issue where pandas pandas.Categorical(,ordered=True) Series were
    not correctly converted to an R ordered factor (#1234).

  • The reticulate Python engine no longer halts on error for Python chunks
    containing parse errors when the error=TRUE chunk option is set. (#583)

  • install_python() now leverages brew for python build dependencies like
    [email protected] if brew is already installed and on the PATH, substantially speeding up
    install_python() on macOS systems with brew configured.

  • Fixed an issue where reticulate would fail to bind to a conda environment on macOS or linux
    if conda installed a non-POSIX compliant activation script into the conda environment. (#1255)

  • Fixed an issue where the python knitr engine would error when printing to
    HTML a constructor of class instances with a _repr_html_ or to_html method
    (e.g., pandas.DataFrame; #1249, #1250).

  • Fixed an issue where the python knitr engine would error when printing a
    plotly figure to an HTML document in some (head-less) linux environments (#1250).

  • Fixed an issue where conda_install(pip=TRUE) would install packages into
    a user Python library instead of the conda env if the environment variable
    PIP_USER=true was set. py_install(), virtualenv_install(), and
    conda_install() now always specify --no-user when invoking pip install. (#1209)

  • Fixed issue where py_last_error() would return unconverted Python objects (#1233)

  • The Knitr engine now supports printing Python objects with
    _repr_markdown_ methods. (via quarto-dev/quarto-cli#1501)

  • sys.executable on Windows now correctly reports the path to the Python executable
    instead of the launching R executable. (#1258)

  • The sys module is no longer automatically imported in __main__ by reticulate.

  • Fixed an issue on Windows where reticulate would fail to find Python installations from pyenv installed via scoop.

  • Fixed an issue where configure_environment() would error on Windows. (#1247)

  • Updated docs for compatibility with HTML5 / R 4.2.

  • Updated r_to_py.sparseMatrix() method for compatibility with Matrix 1.4-2.

reticulate 1.25

11 May 17:35
Compare
Choose a tag to compare
  • Fixed an issue where reticulate would fail if R was running embedded under rpy2.
    reticulate now ensures the Python GIL is acquired before calling into Python.

  • Fixed an issue where reticulate would fail to bind to an ArcGIS Pro conda environment
    (#1200, @philiporlando).

  • Fixed an issue where reticulate would fail to bind to an Anaconda
    base environment on Windows.

  • All commands that create, modify, or delete a Python environment now echo
    the system command about to be executed. Affected:
    virtualenv_{create,install,remove}
    conda_{create,clone,remove,install,update}
    py_install

  • install_python() and create_virtualenv() gain the ability to automatically
    select the latest patch of a requested Python version.
    e.g.: install_python("3.9:latest"), create_virtualenv("my-env", version = "3.9:latest")

  • install_python() version arg gains default value of "3.9:latest".
    install_python() can now be called with no arguments.

  • Fixed an issue where reticulate would fail to bind to a conda python
    if the user didn't have write permissions to the conda installation (#1156).

  • Fixed an issue where reticulate would fail to bind to a conda python if
    spaces were present in the file path to the associated conda binary (#1154).

  • use_python(, required = TRUE) now issues a warning if the request will be ignored (#1150).

  • New function py_repr() (#1157)

  • print() and related changes (#1148, #1157):

    • The default print() method for Python objects now invokes py_repr() instead of str().
    • All Python objects gain a default format() method that invokes py_str().
    • py_str() default method no longer strips the object memory address.
    • print() now returns the printed object invisibly, for composability with %>%.
  • Exception handling changes (#1142, @t-kalinowski):

    • R error messages from Python exceptions are now truncated differently to satisfy getOption("warning.length").
      A hint to call reticulate::py_last_error() is shown if the exception message was truncated.

    • Python buffers sys.stderr and sys.stdout are now flushed when Python exceptions are raised.

    -py_last_error():

    • Return object is now an S3 object 'py_error', includes a default print method.
    • The python Exception object ('python.builtin.Exception') is available as an R attribute.
    • Gains the ability to restore a previous exception if provided in a call py_last_error(previous_error)
    • Python traceback objects gain a default format() S3 method.
  • Fixed py_to_r() for scipy matrices when scipy >= 1.8.0, since sparse matrices
    are now deprecated.

  • Fixed r_to_py() for small scipy matrices.

  • New maintainer: Tomasz Kalinowski