|
16 | 16 | import functools
|
17 | 17 | from io import StringIO
|
18 | 18 | import itertools
|
| 19 | +import sys |
19 | 20 | from textwrap import dedent
|
20 | 21 | from typing import (
|
21 | 22 | TYPE_CHECKING,
|
|
48 | 49 | from pandas._libs.hashtable import duplicated
|
49 | 50 | from pandas._libs.lib import (
|
50 | 51 | NoDefault,
|
51 |
| - array_equal_fast, |
| 52 | + is_range_indexer, |
52 | 53 | no_default,
|
53 | 54 | )
|
54 | 55 | from pandas._typing import (
|
|
91 | 92 | WriteBuffer,
|
92 | 93 | npt,
|
93 | 94 | )
|
| 95 | +from pandas.compat import PYPY |
94 | 96 | from pandas.compat._optional import import_optional_dependency
|
95 | 97 | from pandas.compat.numpy import (
|
96 | 98 | function as nv,
|
97 | 99 | np_percentile_argname,
|
98 | 100 | )
|
99 |
| -from pandas.errors import InvalidIndexError |
| 101 | +from pandas.errors import ( |
| 102 | + ChainedAssignmentError, |
| 103 | + InvalidIndexError, |
| 104 | + _chained_assignment_msg, |
| 105 | +) |
100 | 106 | from pandas.util._decorators import (
|
101 | 107 | Appender,
|
102 | 108 | Substitution,
|
@@ -3862,6 +3868,10 @@ def isetitem(self, loc, value) -> None:
|
3862 | 3868 | self._iset_item_mgr(loc, arraylike, inplace=False)
|
3863 | 3869 |
|
3864 | 3870 | def __setitem__(self, key, value):
|
| 3871 | + if not PYPY and using_copy_on_write(): |
| 3872 | + if sys.getrefcount(self) <= 3: |
| 3873 | + raise ChainedAssignmentError(_chained_assignment_msg) |
| 3874 | + |
3865 | 3875 | key = com.apply_if_callable(key, self)
|
3866 | 3876 |
|
3867 | 3877 | # see if we can slice the rows
|
@@ -6724,7 +6734,7 @@ def sort_values(
|
6724 | 6734 | else:
|
6725 | 6735 | return self.copy(deep=None)
|
6726 | 6736 |
|
6727 |
| - if array_equal_fast(indexer, np.arange(0, len(indexer), dtype=indexer.dtype)): |
| 6737 | + if is_range_indexer(indexer, len(indexer)): |
6728 | 6738 | if inplace:
|
6729 | 6739 | return self._update_inplace(self)
|
6730 | 6740 | else:
|
@@ -6922,8 +6932,8 @@ def value_counts(
|
6922 | 6932 |
|
6923 | 6933 | Parameters
|
6924 | 6934 | ----------
|
6925 |
| - subset : label or list of labels, optional |
6926 |
| - Column(s) to use when counting unique combinations. |
| 6935 | + subset : mapping, function, label, list of labels, optional |
| 6936 | + Columns to use when counting unique combinations. |
6927 | 6937 | normalize : bool, default False
|
6928 | 6938 | Return proportions rather than frequencies.
|
6929 | 6939 | sort : bool, default True
|
@@ -10877,11 +10887,7 @@ def quantile(
|
10877 | 10887 | f"Invalid method: {method}. Method must be in {valid_method}."
|
10878 | 10888 | )
|
10879 | 10889 | if method == "single":
|
10880 |
| - # error: Argument "qs" to "quantile" of "BlockManager" has incompatible type |
10881 |
| - # "Index"; expected "Float64Index" |
10882 |
| - res = data._mgr.quantile( |
10883 |
| - qs=q, axis=1, interpolation=interpolation # type: ignore[arg-type] |
10884 |
| - ) |
| 10890 | + res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation) |
10885 | 10891 | elif method == "table":
|
10886 | 10892 | valid_interpolation = {"nearest", "lower", "higher"}
|
10887 | 10893 | if interpolation not in valid_interpolation:
|
|
0 commit comments