
On Mon, Nov 29, 2021 at 5:15 AM Steven D'Aprano <steve@pearwood.info> wrote:
- the method modifies the object in place, and returns self; - versus the method returns a new, modified, copy of the object. Pandas uses the first style (I think; corrections welcome). Strings use the second, because they have no choice.
Pandas returns SOMETHING when a method is called. Maybe it's self, maybe it's after mutation, maybe it's a new DataFrame, Grouper, Series, etc. Pandas goes out of its way not to promise what gets returned. Indeed, that answer often changes between minor, or even micro, versions of Pandas. I'm not sure I love that fact, but so it is. As a consequence, the Pandas developers have made a "soft deprecation" of the `inplace=True` parameter that most methods take. I still like that style better, often, but they really want to avoid guaranteeing which operations will or won't save memory in the implementation, and feel like that flag can mislead users. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.