Warnings signaled by polars
Description
Some warnings signaled by polars have dedicated classes, so they can be
caught or suppressed selectively with the standard R condition system,
such as suppressWarnings(),
withCallingHandlers() and
globalCallingHandlers().
Warning classes
The following kinds of warnings have one of the classes below and the
polars_warning class. Other warnings, such as those about
unsupported arguments of S3 methods, may not have these classes.
-
polars_deprecation_warning: A deprecated feature was used. Deprecation warnings from the R side also have thelifecycle_warning_deprecatedclass from the lifecycle package. -
polars_breaking_change_warning: A feature affected by a breaking change in a minor or patch release was used. See the section below. -
polars_user_warning,polars_categorical_remapping_warningandpolars_map_without_return_dtype_warning: Warnings signaled by the Polars engine.
Breaking change warnings
The version of R Polars follows the version of the upstream Polars. The upstream Polars may introduce breaking changes in minor releases, for example a change of the results of an existing function, which R Polars cannot avoid without diverging from the upstream. To notify users of such changes, R Polars signals a warning when a feature affected by them is used.
These warnings have the following classes, from the most specific one:
-
polars\_\: The class for the version that introduced the change, e.g.*\ *\ \_breaking_change_warning polars_2_2_0_breaking_change_warningfor polars 2.2.0. It does not depend on the installed version of polars. -
polars_breaking_change_warning -
polars_warning
By default, each warning is signaled only once per session for each change. Note that a warning caught or suppressed by a handler is also counted as signaled.
Breaking change warnings are kept at least throughout the minor release
series that introduced them and the following minor release series
(e.g. warnings added in polars 2.2.0 are kept in 2.2.x and 2.3.x, and
may be removed in 2.4.0 at the earliest). They may be kept longer
depending on the impact of the changes. Removed warnings are listed in
the NEWS of the release that removed them, with the affected functions
and the version-specific class, so you can find
suppressWarnings() calls that are no longer necessary. Note
that warnings sharing a version-specific class may be removed in
different releases, and a suppression is only unnecessary once all the
warnings it targets have been removed in all the versions of polars your
code supports. Specifying the class of a removed warning is harmless.
Once your code has been migrated for the changes in a version, you can suppress the warnings for that version without affecting the warnings for other versions or other kinds of warnings. Leaving a comment about the reason is recommended.
# Already migrated to the change of <what changed> in polars 2.2.0
suppressWarnings(
your_code(),
classes = "polars_2_2_0_breaking_change_warning"
)
# Suppress the warnings for the changes in polars 2.2.0 for the rest of
# the session (this affects all code running in the session)
globalCallingHandlers(
polars_2_2_0_breaking_change_warning = function(cnd) {
invokeRestart("muffleWarning")
}
)
The class polars_breaking_change_warning can be used in the
same way to suppress all breaking change warnings.
Verbosity of breaking change warnings
The option polars.breaking_change_warning_verbosity
controls how often breaking change warnings are signaled. It only
affects breaking change warnings, not other kinds of warnings. Possible
values are:
-
“default”(default): Follow therlib_warning_verbosityoption of the rlang package, i.e. signal each warning only once per session for each change by default. -
“verbose”: Signal the warnings every time, e.g. to find all the code affected by the changes. -
“quiet”: Do not signal the warnings at all. Note that this also hides warnings about changes in future versions, so suppressing the warnings by the version-specific classes is preferred.
options(polars.breaking_change_warning_verbosity = "verbose")
The warnings are signaled through the rlang package, so they are not
signaled when options(rlib_warning_verbosity = “quiet”) is
set, even if this option is “verbose”, and they are
signaled every time when options(rlib_warning_verbosity =
“verbose”) is set, even if this option is “default”.
See rlang::warn() for details.