Comments (6)
I think this can be handled purely on the Python side. Make time_unit
optional and set it based on the value of nanoseconds
.
from polars.
It can also be seen with just pl.duration()
:
>>> pl.LazyFrame().with_columns(pl.duration(nanoseconds=1)).collect()
shape: (1, 1)
┌──────────────┐
│ literal │
│ --- │
│ duration[μs] │
╞══════════════╡
│ 0µs │
└──────────────┘
>>> pl.LazyFrame().with_columns(pl.duration(nanoseconds=1).cast(pl.Int64)).collect()
shape: (1, 1)
┌─────────┐
│ literal │
│ --- │
│ i64 │
╞═════════╡
│ 0 │
└─────────┘
>>> pl.LazyFrame().with_columns(pl.duration(nanoseconds=1).cast(pl.Duration('ns'))).collect()
shape: (1, 1)
┌──────────────┐
│ literal │
│ --- │
│ duration[ns] │
╞══════════════╡
│ 0ns │
└──────────────┘
>>> pl.LazyFrame().with_columns(pl.duration(nanoseconds=1).cast(pl.Duration('ns')).cast(pl.Int64)).collect()
shape: (1, 1)
┌─────────┐
│ literal │
│ --- │
│ i64 │
╞═════════╡
│ 0 │
└─────────┘
from polars.
Note that all seems to fall back in order if pl.duration(..., time_unit='ns')
is specified, so maybe all this needs is a an automatic setting of time_unit that is consistent with the values provided, or an exception if a sub-Xs component is provided when time_unit='Xs'
is specified.
from polars.
This is not a bug, but we can improve the API here. For now, you can specify time_unit='ns'
as you have found.
The default time unit for duration
is microseconds. So pl.duration(nanoseconds=999)
results in a Duration(us)
.
We can possibly improve here by inferring the time unit from the inputs, e.g. if time_unit
is None andnanoseconds
is specified, create a Duration(ns)
.
Adding two durations of different precisions will use the lowest precision to avoid overflows. So the result here is expected.
from polars.
Can I assign this to me?
Any places I should start my work at?
from polars.
Opened PR: #14987
from polars.
Related Issues (20)
- `join_asof` breaks with certain parquet files (I think due to memory layout or something?) HOT 2
- Expressions result in different serializations across Python Polars PATCH version upgrades HOT 1
- Add inline XOR (`^`) operator for selectors HOT 3
- Inconsistency in constructing dataframes with timezone-aware datatypes HOT 8
- "Failed to determine supertype of bool and datetime[ns]" Panic
- suggest sql add `select sth` without a `from` syntax HOT 4
- Unexpected `index out of bounds` error for specific dataset and set of operations HOT 11
- `pl.DataFrame.corr()` should offer an argument "include_column_names_as_column". HOT 5
- Polars String or &str HOT 5
- Add `split` as superset of `slice` on `ChunkedArray`, `DataFrame` and `Series`.
- expose `null_on_oob` on `gather`.
- Identical query behaves differently between Expression API and SQL API regarding `streaming` HOT 1
- update object_store version 0.9 -> 0.10.1 HOT 1
- [QST]: should `pl.Expr.slice` raise if the numeric arguments are not integral HOT 1
- Large hike in memory for .unique on array fields HOT 1
- polars.testing.assert_series_equal has incorrect logic for infinities
- Providing nightly builds ? HOT 2
- Increase the verbosity of Schema and Catalog/DB input arguments to the write_database function.
- polars.exceptions.SchemaError: type Int64 is incompatible with expected type Int32 HOT 4
- pl.DataFrame.corr(method = "spearman") HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polars.