Why aren’t Pandas operations in-place?

As evidenced here in the pandas documentation, “… In general we like to favor immutability where sensible.” The Pandas project is in the camp of preferring immutable (stateless) objects over mutable (objects with state) to guide programmers into creating more scalable / parallelizable data processing code. They are guiding the users by making the ‘inplace=False’ behavior the default.

In this software engineering stack exchange Peter Torok discusses the pros and cons between mutable and immutable object programming really nicely.
https://softwareengineering.stackexchange.com/a/151735

In summary some software engineers feel that objects that are immutable (unchanging) lead to

  • less errors in the code – because object states are easy to lose track of and hard to track down
  • increased scalability – it is easier to write multithreaded code, since one thread will not inadvertently modify the value contained by an object in another thread
  • more concise code – since code is forced to be written in a functional programming and more mathematical style

I will agree that this does have it’s inefficiencies since constantly making copies of the same objects for minor changes does not seem ideal. It has other benefits noted above.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)