Skip to content

Commit 90b086f

Browse files
Merge remote-tracking branch 'upstream/master' into bisect
2 parents b6587c1 + 64e8720 commit 90b086f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+966
-666
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ repos:
2424
hooks:
2525
- id: isort
2626
- repo: https://github.com/asottile/pyupgrade
27-
rev: v2.9.0
27+
rev: v2.10.0
2828
hooks:
2929
- id: pyupgrade
3030
args: [--py37-plus, --keep-runtime-typing]
3131
- repo: https://github.com/pre-commit/pygrep-hooks
32-
rev: v1.7.0
32+
rev: v1.7.1
3333
hooks:
3434
- id: rst-backticks
3535
- id: rst-directive-colons

asv_bench/benchmarks/categoricals.py

+17
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,29 @@ def setup(self):
118118
self.a = pd.Categorical(list("aabbcd") * N)
119119
self.b = pd.Categorical(list("bbcdjk") * N)
120120

121+
self.idx_a = pd.CategoricalIndex(range(N), range(N))
122+
self.idx_b = pd.CategoricalIndex(range(N + 1), range(N + 1))
123+
self.df_a = pd.DataFrame(range(N), columns=["a"], index=self.idx_a)
124+
self.df_b = pd.DataFrame(range(N + 1), columns=["a"], index=self.idx_b)
125+
121126
def time_concat(self):
122127
pd.concat([self.s, self.s])
123128

124129
def time_union(self):
125130
union_categoricals([self.a, self.b])
126131

132+
def time_append_overlapping_index(self):
133+
self.idx_a.append(self.idx_a)
134+
135+
def time_append_non_overlapping_index(self):
136+
self.idx_a.append(self.idx_b)
137+
138+
def time_concat_overlapping_index(self):
139+
pd.concat([self.df_a, self.df_a])
140+
141+
def time_concat_non_overlapping_index(self):
142+
pd.concat([self.df_a, self.df_b])
143+
127144

128145
class ValueCounts:
129146

asv_bench/benchmarks/hash_functions.py

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ def time_isin_outside(self, dtype, exponent):
2525
self.s.isin(self.values_outside)
2626

2727

28+
class UniqueForLargePyObjectInts:
29+
def setup(self):
30+
lst = [x << 32 for x in range(5000)]
31+
self.arr = np.array(lst, dtype=np.object_)
32+
33+
def time_unique(self):
34+
pd.unique(self.arr)
35+
36+
2837
class IsinWithRandomFloat:
2938
params = [
3039
[np.float64, np.object],

doc/source/development/extending.rst

+4-14
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,11 @@ Each data structure has several *constructor properties* for returning a new
329329
data structure as the result of an operation. By overriding these properties,
330330
you can retain subclasses through ``pandas`` data manipulations.
331331

332-
There are 3 constructor properties to be defined:
332+
There are 3 possible constructor properties to be defined on a subclass:
333333

334-
* ``_constructor``: Used when a manipulation result has the same dimensions as the original.
335-
* ``_constructor_sliced``: Used when a manipulation result has one lower dimension(s) as the original, such as ``DataFrame`` single columns slicing.
336-
* ``_constructor_expanddim``: Used when a manipulation result has one higher dimension as the original, such as ``Series.to_frame()``.
337-
338-
Following table shows how ``pandas`` data structures define constructor properties by default.
339-
340-
=========================== ======================= =============
341-
Property Attributes ``Series`` ``DataFrame``
342-
=========================== ======================= =============
343-
``_constructor`` ``Series`` ``DataFrame``
344-
``_constructor_sliced`` ``NotImplementedError`` ``Series``
345-
``_constructor_expanddim`` ``DataFrame`` ``NotImplementedError``
346-
=========================== ======================= =============
334+
* ``DataFrame/Series._constructor``: Used when a manipulation result has the same dimension as the original.
335+
* ``DataFrame._constructor_sliced``: Used when a ``DataFrame`` (sub-)class manipulation result should be a ``Series`` (sub-)class.
336+
* ``Series._constructor_expanddim``: Used when a ``Series`` (sub-)class manipulation result should be a ``DataFrame`` (sub-)class, e.g. ``Series.to_frame()``.
347337

348338
Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame`` overriding constructor properties.
349339

doc/source/whatsnew/v1.2.2.rst

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _whatsnew_122:
22

3-
What's new in 1.2.2 (February ??, 2021)
3+
What's new in 1.2.2 (February 08, 2021)
44
---------------------------------------
55

66
These are the changes in pandas 1.2.2. See :ref:`release` for a full changelog
@@ -17,12 +17,16 @@ Fixed regressions
1717

1818
- Fixed regression in :func:`read_excel` that caused it to raise ``AttributeError`` when checking version of older xlrd versions (:issue:`38955`)
1919
- Fixed regression in :class:`DataFrame` constructor reordering element when construction from datetime ndarray with dtype not ``"datetime64[ns]"`` (:issue:`39422`)
20-
- Fixed regression in :class:`DataFrame.astype` and :class:`Series.astype` not casting to bytes dtype (:issue:`39474`)
20+
- Fixed regression in :meth:`DataFrame.astype` and :meth:`Series.astype` not casting to bytes dtype (:issue:`39474`)
2121
- Fixed regression in :meth:`~DataFrame.to_pickle` failing to create bz2/xz compressed pickle files with ``protocol=5`` (:issue:`39002`)
2222
- Fixed regression in :func:`pandas.testing.assert_series_equal` and :func:`pandas.testing.assert_frame_equal` always raising ``AssertionError`` when comparing extension dtypes (:issue:`39410`)
2323
- Fixed regression in :meth:`~DataFrame.to_csv` opening ``codecs.StreamWriter`` in binary mode instead of in text mode and ignoring user-provided ``mode`` (:issue:`39247`)
24-
- Fixed regression in :meth:`core.window.rolling.Rolling.count` where the ``min_periods`` argument would be set to ``0`` after the operation (:issue:`39554`)
25-
-
24+
- Fixed regression in :meth:`Categorical.astype` casting to incorrect dtype when ``np.int32`` is passed to dtype argument (:issue:`39402`)
25+
- Fixed regression in :meth:`~DataFrame.to_excel` creating corrupt files when appending (``mode="a"``) to an existing file (:issue:`39576`)
26+
- Fixed regression in :meth:`DataFrame.transform` failing in case of an empty DataFrame or Series (:issue:`39636`)
27+
- Fixed regression in :meth:`~DataFrame.groupby` or :meth:`~DataFrame.resample` when aggregating an all-NaN or numeric object dtype column (:issue:`39329`)
28+
- Fixed regression in :meth:`.Rolling.count` where the ``min_periods`` argument would be set to ``0`` after the operation (:issue:`39554`)
29+
- Fixed regression in :func:`read_excel` that incorrectly raised when the argument ``io`` was a non-path and non-buffer and the ``engine`` argument was specified (:issue:`39528`)
2630

2731
.. ---------------------------------------------------------------------------
2832
@@ -33,17 +37,7 @@ Bug fixes
3337

3438
- :func:`pandas.read_excel` error message when a specified ``sheetname`` does not exist is now uniform across engines (:issue:`39250`)
3539
- Fixed bug in :func:`pandas.read_excel` producing incorrect results when the engine ``openpyxl`` is used and the excel file is missing or has incorrect dimension information; the fix requires ``openpyxl`` >= 3.0.0, prior versions may still fail (:issue:`38956`, :issue:`39001`)
36-
-
37-
38-
.. ---------------------------------------------------------------------------
39-
40-
.. _whatsnew_122.other:
41-
42-
Other
43-
~~~~~
44-
45-
-
46-
-
40+
- Fixed bug in :func:`pandas.read_excel` sometimes producing a ``DataFrame`` with trailing rows of ``np.nan`` when the engine ``openpyxl`` is used (:issue:`39181`)
4741

4842
.. ---------------------------------------------------------------------------
4943

doc/source/whatsnew/v1.3.0.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor
219219
Other API changes
220220
^^^^^^^^^^^^^^^^^
221221
- Partially initialized :class:`CategoricalDtype` (i.e. those with ``categories=None`` objects will no longer compare as equal to fully initialized dtype objects.
222-
-
222+
- Accessing ``_constructor_expanddim`` on a :class:`DataFrame` and ``_constructor_sliced`` on a :class:`Series` now raise an ``AttributeError``. Previously a ``NotImplementedError`` was raised (:issue:`38782`)
223223
-
224224

225225
.. ---------------------------------------------------------------------------
@@ -253,6 +253,7 @@ Performance improvements
253253
- Performance improvement in :meth:`DataFrame.corr` for method=kendall (:issue:`28329`)
254254
- Performance improvement in :meth:`core.window.rolling.Rolling.corr` and :meth:`core.window.rolling.Rolling.cov` (:issue:`39388`)
255255
- Performance improvement in :meth:`core.window.rolling.RollingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr` and :meth:`core.window.expanding.ExpandingGroupby.cov` (:issue:`39591`)
256+
- Performance improvement in :func:`unique` for object data type (:issue:`37615`)
256257

257258
.. ---------------------------------------------------------------------------
258259
@@ -304,6 +305,7 @@ Numeric
304305
- Bug in :meth:`DataFrame.mode` and :meth:`Series.mode` not keeping consistent integer :class:`Index` for empty input (:issue:`33321`)
305306
- Bug in :meth:`DataFrame.rank` with ``np.inf`` and mixture of ``np.nan`` and ``np.inf`` (:issue:`32593`)
306307
- Bug in :meth:`DataFrame.rank` with ``axis=0`` and columns holding incomparable types raising ``IndexError`` (:issue:`38932`)
308+
- Bug in :func:`select_dtypes` different behavior between Windows and Linux with ``include="int"`` (:issue:`36569`)
307309
-
308310

309311
Conversion
@@ -338,7 +340,7 @@ Indexing
338340
- Bug in :meth:`Series.__setitem__` raising ``ValueError`` when setting a :class:`Series` with a scalar indexer (:issue:`38303`)
339341
- Bug in :meth:`DataFrame.loc` dropping levels of :class:`MultiIndex` when :class:`DataFrame` used as input has only one row (:issue:`10521`)
340342
- Bug in :meth:`DataFrame.__getitem__` and :meth:`Series.__getitem__` always raising ``KeyError`` when slicing with existing strings an :class:`Index` with milliseconds (:issue:`33589`)
341-
- Bug in setting ``timedelta64`` values into numeric :class:`Series` failing to cast to object dtype (:issue:`39086`)
343+
- Bug in setting ``timedelta64`` or ``datetime64`` values into numeric :class:`Series` failing to cast to object dtype (:issue:`39086`, issue:`39619`)
342344
- Bug in setting :class:`Interval` values into a :class:`Series` or :class:`DataFrame` with mismatched :class:`IntervalDtype` incorrectly casting the new values to the existing dtype (:issue:`39120`)
343345
- Bug in setting ``datetime64`` values into a :class:`Series` with integer-dtype incorrect casting the datetime64 values to integers (:issue:`39266`)
344346
- Bug in :meth:`Index.get_loc` not raising ``KeyError`` when method is specified for ``NaN`` value when ``NaN`` is not in :class:`Index` (:issue:`39382`)
@@ -445,10 +447,11 @@ Other
445447
- Bug in :class:`Index` constructor sometimes silently ignorning a specified ``dtype`` (:issue:`38879`)
446448
- Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`)
447449
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`)
450+
- ``inspect.getmembers(Series)`` no longer raises an ``AbstractMethodError`` (:issue:`38782`)
448451
- :meth:`Index.where` behavior now mirrors :meth:`Index.putmask` behavior, i.e. ``index.where(mask, other)`` matches ``index.putmask(~mask, other)`` (:issue:`39412`)
449452
- Bug in :func:`pandas.testing.assert_series_equal`, :func:`pandas.testing.assert_frame_equal`, :func:`pandas.testing.assert_index_equal` and :func:`pandas.testing.assert_extension_array_equal` incorrectly raising when an attribute has an unrecognized NA type (:issue:`39461`)
450453
- Bug in :class:`Styler` where ``subset`` arg in methods raised an error for some valid multiindex slices (:issue:`33562`)
451-
-
454+
- :class:`Styler` rendered HTML output minor alterations to support w3 good code standard (:issue:`39626`)
452455
-
453456

454457
.. ---------------------------------------------------------------------------

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ dependencies:
113113
- tabulate>=0.8.3 # DataFrame.to_markdown
114114
- natsort # DataFrame.sort_values
115115
- pip:
116-
- git+https://github.com/pandas-dev/pydata-sphinx-theme.git@master
116+
- git+https://github.com/pandas-dev/pydata-sphinx-theme.git@2488b7defbd3d753dd5fcfc890fc4a7e79d25103
117117
- git+https://github.com/numpy/numpydoc

pandas/_libs/index_class_helper.pxi.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ cdef class {{name}}Engine(IndexEngine):
3434
cdef _make_hash_table(self, Py_ssize_t n):
3535
return _hash.{{name}}HashTable(n)
3636

37-
{{if name not in {'Float64', 'Float32'} }}
3837
cdef _check_type(self, object val):
38+
{{if name not in {'Float64', 'Float32'} }}
3939
if not util.is_integer_object(val):
4040
raise KeyError(val)
41+
{{else}}
42+
if util.is_bool_object(val):
43+
# avoid casting to True -> 1.0
44+
raise KeyError(val)
4145
{{endif}}
4246

4347
cdef void _call_map_locations(self, values):

pandas/_libs/src/klib/khash_python.h

+25-5
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,31 @@ int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b) {
178178
return result;
179179
}
180180

181-
// For PyObject_Hash holds:
182-
// hash(0.0) == 0 == hash(-0.0)
183-
// hash(X) == 0 if X is a NaN-value
184-
// so it is OK to use it directly
185-
#define kh_python_hash_func(key) (PyObject_Hash(key))
181+
182+
khint32_t PANDAS_INLINE kh_python_hash_func(PyObject* key){
183+
// For PyObject_Hash holds:
184+
// hash(0.0) == 0 == hash(-0.0)
185+
// hash(X) == 0 if X is a NaN-value
186+
// so it is OK to use it directly for doubles
187+
Py_hash_t hash = PyObject_Hash(key);
188+
if (hash == -1) {
189+
PyErr_Clear();
190+
return 0;
191+
}
192+
#if SIZEOF_PY_HASH_T == 4
193+
// it is already 32bit value
194+
return hash;
195+
#else
196+
// for 64bit builds,
197+
// we need information of the upper 32bits as well
198+
// see GH 37615
199+
khuint64_t as_uint = (khuint64_t) hash;
200+
// uints avoid undefined behavior of signed ints
201+
return (as_uint>>32)^as_uint;
202+
#endif
203+
}
204+
205+
186206
#define kh_python_hash_equal(a, b) (pyobject_cmp(a, b))
187207

188208

pandas/conftest.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""
2020

2121
from collections import abc
22-
from datetime import date, time, timedelta, timezone
22+
from datetime import date, datetime, time, timedelta, timezone
2323
from decimal import Decimal
2424
import operator
2525
import os
@@ -757,6 +757,27 @@ def mixed_type_frame():
757757
)
758758

759759

760+
@pytest.fixture
761+
def rand_series_with_duplicate_datetimeindex():
762+
"""
763+
Fixture for Series with a DatetimeIndex that has duplicates.
764+
"""
765+
dates = [
766+
datetime(2000, 1, 2),
767+
datetime(2000, 1, 2),
768+
datetime(2000, 1, 2),
769+
datetime(2000, 1, 3),
770+
datetime(2000, 1, 3),
771+
datetime(2000, 1, 3),
772+
datetime(2000, 1, 4),
773+
datetime(2000, 1, 4),
774+
datetime(2000, 1, 4),
775+
datetime(2000, 1, 5),
776+
]
777+
778+
return Series(np.random.randn(len(dates)), index=dates)
779+
780+
760781
# ----------------------------------------------------------------
761782
# Scalars
762783
# ----------------------------------------------------------------
@@ -1242,6 +1263,32 @@ def any_nullable_int_dtype(request):
12421263
return request.param
12431264

12441265

1266+
@pytest.fixture(params=tm.ALL_INT_DTYPES + tm.ALL_EA_INT_DTYPES)
1267+
def any_int_or_nullable_int_dtype(request):
1268+
"""
1269+
Parameterized fixture for any nullable integer dtype.
1270+
1271+
* int
1272+
* 'int8'
1273+
* 'uint8'
1274+
* 'int16'
1275+
* 'uint16'
1276+
* 'int32'
1277+
* 'uint32'
1278+
* 'int64'
1279+
* 'uint64'
1280+
* 'UInt8'
1281+
* 'Int8'
1282+
* 'UInt16'
1283+
* 'Int16'
1284+
* 'UInt32'
1285+
* 'Int32'
1286+
* 'UInt64'
1287+
* 'Int64'
1288+
"""
1289+
return request.param
1290+
1291+
12451292
@pytest.fixture(params=tm.ALL_EA_INT_DTYPES + tm.FLOAT_EA_DTYPES)
12461293
def any_nullable_numeric_dtype(request):
12471294
"""

pandas/core/aggregation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def transform(
457457

458458
# Functions that transform may return empty Series/DataFrame
459459
# when the dtype is not appropriate
460-
if isinstance(result, (ABCSeries, ABCDataFrame)) and result.empty:
460+
if isinstance(result, (ABCSeries, ABCDataFrame)) and result.empty and not obj.empty:
461461
raise ValueError("Transform function failed")
462462
if not isinstance(result, (ABCSeries, ABCDataFrame)) or not result.index.equals(
463463
obj.index

pandas/core/algorithms.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ def unique(values):
324324
Hash table-based unique. Uniques are returned in order
325325
of appearance. This does NOT sort.
326326
327-
Significantly faster than numpy.unique. Includes NA values.
327+
Significantly faster than numpy.unique for long enough sequences.
328+
Includes NA values.
328329
329330
Parameters
330331
----------

0 commit comments

Comments
 (0)