Comments (1)
I think this behavior comes from how polars adds constants to data frames.
Python's sum
has a starting value, which defaults to zero. The call sum([a, b])
runs as (0 + a) + b
.
When polars goes to add 0
to your first DataFrame
, it creates a Series
from the constant and infers an i64
type. Apparently, polars allows adding integers to dates, casting the date to an integer using the number of days since the epoch. When you add the second dataframe, addition doesn't crash because i64
+ date is allowed, even though date + date is not.
If you change the sum's starting value, you can get different types or different values:
>>> sum(
... [pl.DataFrame({'x':[1]}).cast({'x':pl.Date}), pl.DataFrame({'x':[2]}).cast({'x':pl.Date})],
... start=0.0,
... )
┌─────┐
│ x │
│ --- │
│ f64 │
╞═════╡
│ 3.0 │
└─────┘
>>> sum(
... [pl.DataFrame({'x':[1]}).cast({'x':pl.Date}), pl.DataFrame({'x':[2]}).cast({'x':pl.Date})],
... start=10,
... )
┌─────┐
│ x │
│ --- │
│ i64 │
╞═════╡
│ 13 │
└─────┘
The conversion of dates to integers is pretty weird:
>>> sum([pl.DataFrame({'x':[date(2024, 4, 1)]})])
┌───────┐
│ x │
│ --- │
│ i64 │
╞═══════╡
│ 19814 │
└───────┘
from polars.
Related Issues (20)
- Add `make test-ci` to (mostly) replicate CI tests HOT 4
- Allow use of ParquetWriter, ParquetReader w/o compiling all compression deps (WASM support) HOT 8
- rename π to selected_columns and σ to filters in logal graph dot? HOT 4
- Add `polars.Expr.list.drop_nans()` HOT 2
- `read_parquet` don't recognize OSS url scheme HOT 1
- Not clear if Parquet statistics are used when filter applied HOT 2
- `bottom_k` should not include nulls if the column contains at least `k` valid elements
- Construct CsvReader from bytestream using CsvReadOptions
- segfault when reading msql using arrow-odbc HOT 1
- `implode` results in extra level of nesting when run within a `group_by(...).agg` HOT 2
- Support reading directly from zipfile.Path objects. HOT 2
- Read_json panics when infer_schema_length = 0
- `explain(streaming=True)` isn't showing correct plan
- Data in csv files with less columns than schema shifts data. HOT 4
- Add the argument `ignore_nulls` in `.arr.all()`, `.arr.any()`, `.list.all()` and `.list.any()`
- read_database_uri panics for dates beyond 2262.04.11 HOT 2
- Move streaming engine original plan to separate field on the `IRPlan`
- Write upgrade guide for 1.0.0
- Polars is unable to parse dates beyond 2262.04.11 HOT 1
- Make a ParquetWriter context handler and/or more control over row group creation
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.