Comments (2)
@MarcoGorelli I'll add this alternative method which is faster than the current solution if you choose to continue on this issue in the future:
import pandas as pd
import polars as pl
num_rows = 1000000
utc_time = pd.date_range(start='2023-01-01', periods=num_rows, freq='s')
df = pd.DataFrame({
'UTC_Time': utc_time
})
df['UTC_Time'] = df['UTC_Time'].sort_values()
print(df.head())
df = pl.DataFrame(df)
df = df.with_columns(pl.col("UTC_Time").dt.truncate("2m").alias("Method1"))
df = df.with_columns(pl.from_epoch((pl.col("UTC_Time")
.dt.epoch(time_unit="ns")
// (2 * 60 * 1_000_000_000))
* (2 * 60 * 1_000_000_000),
time_unit="ns").alias("Method2"))
%timeit df.with_columns(pl.col("UTC_Time").dt.truncate("2m"))
%timeit df.with_columns(pl.from_epoch((pl.col("UTC_Time").dt.epoch(time_unit="ns") // (2 * 60 * 1_000_000_000)) * (2 * 60 * 1_000_000_000), time_unit="ns"))
Console print:
4.62 ms ± 989 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
2.63 ms ± 178 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
This was done on the latest version 1.0.0 alpha version 1.
from polars.
thanks - i'm seeing a much smaller difference though
3.16 ms ± 77.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
2.61 ms ± 186 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
from polars.
Related Issues (20)
- fold shouldn't require that acc and exprs share the same dtype
- Adding `descending` parameter to `Expr.over` HOT 5
- polars.LazyFrame.head recommends using fetch() HOT 1
- Reading large json file error: ComputeError: InputTooLarge at character 0
- Serialize for AnyType has a todo!() HOT 1
- File cache invalidation not triggered for HTTP if size is the same
- Loading parquet written from an Arrow table produces non-deterministic incorrect numbers since 1.2.0 HOT 3
- illegal hardware instruction with python 3.12.4 and polars 1.1.0 on MacOS Sanoma 14, M2 HOT 4
- Panic when call `hash()` on `struct` dtype HOT 2
- Multiple - Reading into a single DataFrame - read_csv - Error when using encoding = latin1 HOT 2
- Big integer error HOT 1
- Add a `newline` parameter to `read_csv` HOT 3
- `sort_by` + `struct` + `exclude` index out of bounds PanicException HOT 1
- CSV Downloads Fail for ADLS Gen2 with Azure CLI Authentication HOT 4
- Panic on datetime column min() HOT 1
- High memory usage after `collect()` despite using `limit(1)`
- Conda package outdated HOT 1
- DateFrame.describe() reports datetime as str HOT 2
- pl.list,len() - pl.list,len() always returning u32 no matter the results HOT 5
- [FEA]: Allow specifying null location in `set_sorted`
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.