Cannot find datetime_ranges function in Polars despite matching documentation

I'm trying to use the datetime_ranges function from Polars as shown in their documentation, but I'm running into compilation issues:

According to the docs, this function should be available when using the lazy and dtype-datetime features:

pub fn datetime_ranges(
    start: Expr,
    end: Expr,
    interval: Duration,
    closed: ClosedWindow,
    time_unit: Option<TimeUnit>,
    time_zone: Option<TimeZone>,
) -> Expr

Here's my current setup:

// Dependencies in Cargo.toml
polars = {version="0.45.1", features = ["lazy", "dtype-datetime", "parquet", "is_in", "polars-io", "strings", "round_series", "polars-ops", "temporal", "offset_by", "dtype-array","concat_str", "asof_join", "cross_join"]}

// In my code
use polars::lazy::dsl::*;
use polars::prelude::*;

// Trying to use it like this:
let windows: LazyFrame = windows.with_column(datetime_ranges(
    col("window_start_min"),
    col("window_end_max"),
    granularity,
    ClosedWindow::Both,
    TimeUnit::Milliseconds,
    None,
));

However, I'm getting the error:

cannot find function datetime_ranges in this scope

And when trying to explicitly import it:

unresolved import polars::prelude::datetime_ranges
no datetime_ranges in prelude

What am I missing here?

It seems like you are doing everything right. Could you please post the output of cargo tree -e features? I’m a little bit suspicious that there might be a bug in polars’ internal feature dependencies (multi-package libraries with many features are very hard to fully test) and this will help determine if that’s true.

Also, please run cargo check and post the entire output of it, not just the first lines. There may be clues there too.

1 Like

Try adding the range feature. doc_auto_cfg—which polars uses to generate the nice required-features-box in the docs—is still unstable and might not get every required feature right on re-exports.

3 Likes

Thank you both for the quick help. Adding range was the solution.

Are there any tricks you use to find these features, i.e., can I find out what I am missing if I get a similar error again?

1 Like

Most projects are not as complex as polars is (and don't overuse the prelude as much), so I hardly ever had a problem finding a missing feature before. In this case I went chasing it down in the source code. This was fairly easy, requiring me to look at just a few lines of re-exports in a handful of files. Another option I use when I don't mind extra bloat (to quickly get an example snippet done for this forum, for example) is to just use a cumulative feature, like full in the case of polars, that enables most if not all the functionality of the crate in question.

2 Likes