Comments (5)
Tried to reproduce. Your example for .round on a Series fails for me as well, however rounding single timedeltas (e.g. pd.Timedelta('1 days 23:18:00').round('d')
) works fine.
from pandas.
Thanks for the report! Result of a git bisect:
commit 6dbeeb4009bbfac5ea1ae2111346f5e9f05b81f4
Author: Lumberbot (aka Jack)
Date: Mon Jan 8 23:24:22 2024 +0100
Backport PR #56767 on branch 2.2.x (BUG: Series.round raising for nullable bool dtype) (#56782)
Backport PR #56767: BUG: Series.round raising for nullable bool dtype
Co-authored-by: Patrick Hoefler
cc @phofl
Note that ser.dt.round('d')
still works. I don't believe that Series.round
having special logic for different dtypes is documented anywhere.
from pandas.
Yeah this is a bit weird, DataFrame.round never worked for those, Series.round now follows this behavior. We can either make both work or keep as is
from pandas.
Making this work for DataFrame.round seems undesirable - numeric columns would take the number of digits as an argument whereas timedelta/datetime would take a frequency. I'd lean toward keeping this as-is.
from pandas.
I have encountered the same issue, but then with datetimes. And as @rhshadrach already mentioned, it matters if you use .round()
or .dt.round()
:
import pandas as pd
dtindex = pd.date_range("2010-01-01", "2010-01-01 12:00", periods=3)
df = pd.DataFrame()
df["datetimes"] = dtindex
df["round_1"] = df["datetimes"].round('d') # this does not round in pandas 2.2.0, it did in pandas<=2.1.4
df["round_2"] = df["datetimes"].dt.round('d')
print(df)
These two rounding methods produce different results with pandas>=2.2.0
:
datetimes round_1 round_2
0 2010-01-01 00:00:00 2010-01-01 00:00:00 2010-01-01
1 2010-01-01 06:00:00 2010-01-01 06:00:00 2010-01-01
2 2010-01-01 12:00:00 2010-01-01 12:00:00 2010-01-01
In pandas<=2.1.4
the two rounding methods produce the same results:
datetimes round_1 round_2
0 2010-01-01 00:00:00 2010-01-01 2010-01-01
1 2010-01-01 06:00:00 2010-01-01 2010-01-01
2 2010-01-01 12:00:00 2010-01-01 2010-01-01
from pandas.
Related Issues (20)
- BUG: None becomes empty string when writing multiple columns to CSV, but double quotes "" when writing single columns HOT 3
- BUG: Unable to import `pandas` when `pyarrow` 16.1.0 is installed HOT 5
- BUG: datetime64[s] data changes when put into HDFStore HOT 1
- BUG: random crash / hang when calculating rolling sum HOT 2
- BUG: 0/0 with arrow backend is not "NA" HOT 4
- BUG: pivot_table chokes on pd.DatetimeTZDtype if there are no rows.
- DOC: "Accelerated operations" talks about speedup in obsolete versions of Pandas HOT 9
- BUG: rounding datetime in series is broken HOT 1
- BUG: DataFrame to JSON failed when it with UUID HOT 4
- ENH: merge_asof with "how” functionality
- ENH: is it possible to save a reference to a method depending on the version HOT 3
- ValueError: Usecols do not match columns, columns expected but not found: ['Col3', 'Col1'] HOT 6
- ENH: Query function to have a star * for all columns HOT 2
- BUG: read_html returns empty list HOT 3
- database is locked HOT 1
- BUG: Enlarging multilevel index fails if one or more level keys are None HOT 2
- BUG: `.dt.microsecond` for pyarrow-backed Series returns 0 HOT 2
- VOTE: Voting issue for PDEP-14: Dedicated string data type for pandas 3.0 HOT 14
- DEPR: `keep_default_dates` and `convert_dates` in `read_json` HOT 6
- ENH: Add Option to Include Array Offset as MultiIndex Level in `explode()` HOT 9
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 pandas.