Skip to content

Latest commit

 

History

History
274 lines (180 loc) · 4.14 KB

v1.3.0.rst

File metadata and controls

274 lines (180 loc) · 4.14 KB

What's new in 1.3.0 (??)

These are the changes in pandas 1.3.0. See :ref:`release` for a full changelog including other versions of pandas.

{{ header }}

Enhancements

Other enhancements

Notable bug fixes

These are bug fixes that might have notable behavior changes.

Assigning with DataFrame.__setitem__ consistently creates a new array

Assigning values with DataFrame.__setitem__ now consistently assigns a new array, rather than mutating inplace (:issue:`33457`, :issue:`35271`, :issue:`35266`)

Previously, DataFrame.__setitem__ would sometimes operate inplace on the underlying array, and sometimes assign a new array. Fixing this inconsistency can have behavior-changing implications for workloads that relied on inplace mutation. The two most common cases are creating a DataFrame from an array and slicing a DataFrame.

Previous Behavior

The array would be mutated inplace for some dtypes, like NumPy's int64 dtype.

>>> import pandas as pd
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> df = pd.DataFrame(a, columns=['a'])
>>> df['a'] = 0
>>> a  # mutated inplace
array([0, 0, 0])

But not others, like :class:`Int64Dtype`.

>>> import pandas as pd
>>> import numpy as np
>>> a = pd.array([1, 2, 3], dtype="Int64")
>>> df = pd.DataFrame(a, columns=['a'])
>>> df['a'] = 0
>>> a  # not mutated
<IntegerArray>
[1, 2, 3]
Length: 3, dtype: Int64

New Behavior

In pandas 1.3.0, DataFrame.__setitem__ consistently sets on a new array rather than mutating the existing array inplace.

For NumPy's int64 dtype

.. ipython:: python

   import pandas as pd
   import numpy as np
   a = np.array([1, 2, 3])
   df = pd.DataFrame(a, columns=['a'])
   df['a'] = 0
   a  # not mutated

For :class:`Int64Dtype`.

.. ipython:: python

   import pandas as pd
   import numpy as np
   a = pd.array([1, 2, 3], dtype="Int64")
   df = pd.DataFrame(a, columns=['a'])
   df['a'] = 0
   a  # not mutated

This also affects cases where a second Series or DataFrame is a view on a first DataFrame.

df = pd.DataFrame({"A": [1, 2, 3]})
df2 = df[['A']]
df['A'] = np.array([0, 0, 0])

Previously, whether df2 was mutated depending on the dtype of the array being assigned to. Now, a new array is consistently assigned, so df2 is not mutated.

Increased minimum versions for dependencies

Other API changes

Deprecations

Performance improvements

Bug fixes

Categorical

Datetimelike

Timedelta

Timezones

Numeric

Conversion

Strings

Interval

Indexing

Missing

MultiIndex

I/O

Period

Plotting

Groupby/resample/rolling

Reshaping

Sparse

ExtensionArray

Other

Contributors