You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you call the new round method on a mixed dataframe (not only numerical columns), you get an error:
In [1]: df = pd.DataFrame({'floats':[0.123, 0.156, 5.687], 'strings': ['a', 'b', 'c']})
In [2]: df.round(2)
TypeError: can't multiply sequence by non-int of type 'float'
In [3]: df.round()
AttributeError: 'str' object has no attribute 'rint'
Would it be better to ignore these non-numerical columns instead of raising an error?
Another option would be to drop these columns (like numerical aggregations like df.mean() do).
The text was updated successfully, but these errors were encountered:
There is indeed new support for rounding datetime64 series, but the problem is that this goes through the accessor method .dt.round() and not .round(). So it is not really obvious how to integrate that.
In [1]: df = pd.DataFrame({'floats':[0.123, 0.156, 5.687], 'dates':pd.date_range('2012-01-01', periods=3)})
In [3]: df.round(2)
TypeError: ufunc multiply cannot use operands with types dtype('<M8[ns]') and dtype('float64')
In [4]: df['dates'].round()
TypeError: ufunc 'rint' not supported for the input types, and the inputs could
not be safely coerced to any supported types according to the casting rule ''safe''
That's a bit in general a problem with specific dtypes that have specialized versions of standard methods requiring other keywords.
Because we could also give access to datetime rounding through Series.round() instead of Series.dt.round()?
In any case, that is maybe another discussion, so for now I would say to also ignore datetime and period columns.
.round should only apply to float/int columns normally. I would simply skip all others (but include them in the return). I think we could pass thru the freq kw to DataFrame.round to handle datetimelike rounding.
further Series.roundcould defer to .dt. for .round behavior of datetimelikes (and with the freq arg non-optional in that case). we can make that another issue I think.
If you call the new
round
method on a mixed dataframe (not only numerical columns), you get an error:Would it be better to ignore these non-numerical columns instead of raising an error?
Another option would be to drop these columns (like numerical aggregations like
df.mean()
do).The text was updated successfully, but these errors were encountered: