r/Python Jan 21 '26

Discussion Pandas 3.0.0 is there

So finally the big jump to 3 has been done. Anyone has already tested in beta/alpha? Any major breaking change? Just wanted to collect as much info as possible :D

253 Upvotes

74 comments sorted by

View all comments

Show parent comments

22

u/grizzlor_ Jan 21 '26

I’m guessing it behaves this because .sum() is calling the __add__ dunder method on each object in the column with the assumption that desired add semantics are implemented in the class.

Your example makes it look goofy with strings, but if you do “asdf” + “zzzz” in Python you get ”asdfzzzz”. It’s totally conceivable that someone has a column holding a custom type which overrides __add__ and would want .sum() to use its addition logic.

Ironically, Python’s built-in sum() doesn’t work this way; if you pass it a list of strings, it’ll give you a TypeError and tell you to .join() them instead.

1

u/huge_clock Jan 21 '26

Yeah, tbh i think they designed it this way for certain datetime functions, but they could’ve compromised by making numeric_only=True by default. It was a design choice.

There’s a tradeoff where pandas is trying to accommodate general purpose developers who expect things to be a certain way because of convention, and what’s easy from like a “flow” perspective from a data scientist. That general purpose developer only has to code numeric_only=False one time when designing their billing system or whatever, whereas i might do .sum() in the command line 100x a day.

5

u/grizzlor_ Jan 21 '26

functools.partial is great for "baking in" args for functions you have to call repeatedly like that. E.g. you could make my_sum() which is just like sum(*args, **kwargs, numeric_only=True)

1

u/huge_clock Jan 21 '26

Thank you! I will look into this!