-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add linear_space
#20678
base: main
Are you sure you want to change the base?
feat: Add linear_space
#20678
Conversation
|
||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, IntoStaticStr)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved ClosedInterval
into linear_space
since it's feature-gated here and I wanted to re-use it. I'm not sure if there's a better place for it.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20678 +/- ##
==========================================
- Coverage 79.92% 79.71% -0.21%
==========================================
Files 1559 1564 +5
Lines 221181 222103 +922
Branches 2530 2531 +1
==========================================
+ Hits 176774 177056 +282
- Misses 43825 44465 +640
Partials 582 582 ☔ View full report in Codecov by Sentry. |
I wasn't sure about that one myself. Will update. |
@mcrumiller I changed my mind right after and deleted my comment, but I guess I wasn't fast enough. I think it's alright to have - equidistant points over the range, not including either start or end. I'm not sure about the name |
I was thinking about this as well. A better-suited parameter name might be something like I grabbed the interval enumeration from |
Let's keep using the established closed terminology then. |
Sure. Do you have any comments on improvements? Should we include a return 'dtype' parameter like in numpy's implementation? |
Rust side mostly looks good to me. I don't think we need a dtype parameter at this time. However I think there's still a couple things missing around dtypes:
|
d64b15c
to
97bbae8
Compare
@orlp, latest round of updates addressing your suggestions:
I've added separate floating implementations (I originally went for generics but it felt messy to me, so I just made two separate implementations). Included new tests.
I've added a temporal path. start/end points with dates produces a
Done--only numeric/temporal work. Again, the start/end must match, and anything outside of these dtypes throws an Exception. |
closed: ClosedInterval = "both", | ||
eager: bool = False, | ||
) -> Expr | Series: | ||
"""Linearly-spaced elements.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the documentation could be a bit better, perhaps with an example for start = 0, end = 1
, num_samples = 4
for each of the closed
options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep forgot docstrings.
@orlp I think we may want |
@mcrumiller Yes, I agree, but it must resolve to a single value, similar to this error: >>> df = pl.DataFrame({"x": [1, 2, 3]})
>>> df.select(pl.int_range(0, pl.col.x))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/orlp/.localpython/lib/python3.11/site-packages/polars/dataframe/frame.py", line 9323, in select
return self.lazy().select(*exprs, **named_exprs).collect(_eager=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/orlp/.localpython/lib/python3.11/site-packages/polars/lazyframe/frame.py", line 2057, in collect
return wrap_df(ldf.collect(callback))
^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ComputeError: `end` must contain exactly one value, got 3 values |
b428afc
to
2f39ae6
Compare
2f39ae6
to
6627366
Compare
@orlp updated |
First pass at #5255.
Update: linear space with temporals is now implemented, along with an
f32
path, and stronger testing.I kept the name
linear_space
since that's a more canonical polars name, althoughlinspace
is far more recognizable. The usage is fairly simple, and theclosed
is one ofboth
(default),left
,right
, ornone
. In each case, the number of samples asked for is provided.