Skip to content

Commit faf2252

Browse files
authored
Merge branch 'master' into move-info
2 parents 35a552a + 3118576 commit faf2252

File tree

156 files changed

+1434
-1188
lines changed

Some content is hidden

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

156 files changed

+1434
-1188
lines changed

ci/code_checks.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ fi
259259
if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
260260

261261
MSG='Doctests frame.py' ; echo $MSG
262-
pytest -q --doctest-modules pandas/core/frame.py \
263-
-k" -itertuples -join -reindex -reindex_axis -round"
262+
pytest -q --doctest-modules pandas/core/frame.py
264263
RET=$(($RET + $?)) ; echo $MSG "DONE"
265264

266265
MSG='Doctests series.py' ; echo $MSG
@@ -294,8 +293,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
294293
MSG='Doctests interval classes' ; echo $MSG
295294
pytest -q --doctest-modules \
296295
pandas/core/indexes/interval.py \
297-
pandas/core/arrays/interval.py \
298-
-k"-from_arrays -from_breaks -from_intervals -from_tuples -set_closed -to_tuples -interval_range"
296+
pandas/core/arrays/interval.py
299297
RET=$(($RET + $?)) ; echo $MSG "DONE"
300298

301299
MSG='Doctests arrays'; echo $MSG

pandas/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
_np_version_under1p16,
2626
_np_version_under1p17,
2727
_np_version_under1p18,
28+
_is_numpy_dev,
2829
)
2930

3031
try:

pandas/_config/config.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282

8383

8484
class OptionError(AttributeError, KeyError):
85-
"""Exception for pandas.options, backwards compatible with KeyError
85+
"""
86+
Exception for pandas.options, backwards compatible with KeyError
8687
checks
8788
"""
8889

@@ -395,7 +396,6 @@ class option_context:
395396
396397
Examples
397398
--------
398-
399399
>>> with option_context('display.max_rows', 10, 'display.max_columns', 5):
400400
... ...
401401
"""
@@ -546,7 +546,8 @@ def deprecate_option(
546546

547547

548548
def _select_options(pat: str) -> List[str]:
549-
"""returns a list of keys matching `pat`
549+
"""
550+
returns a list of keys matching `pat`
550551
551552
if pat=="all", returns all registered options
552553
"""
@@ -709,15 +710,16 @@ def pp(name: str, ks: Iterable[str]) -> List[str]:
709710

710711
@contextmanager
711712
def config_prefix(prefix):
712-
"""contextmanager for multiple invocations of API with a common prefix
713+
"""
714+
contextmanager for multiple invocations of API with a common prefix
713715
714716
supported API functions: (register / get / set )__option
715717
716718
Warning: This is not thread - safe, and won't work properly if you import
717719
the API functions into your module using the "from x import y" construct.
718720
719-
Example:
720-
721+
Example
722+
-------
721723
import pandas._config.config as cf
722724
with cf.config_prefix("display.font"):
723725
cf.register_option("color", "red")

pandas/_libs/lib.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool:
571571
if PyArray_Check(x) and PyArray_Check(y):
572572
if not array_equivalent_object(x, y):
573573
return False
574+
elif (x is C_NA) ^ (y is C_NA):
575+
return False
574576
elif not (PyObject_RichCompareBool(x, y, Py_EQ) or
575577
(x is None or is_nan(x)) and (y is None or is_nan(y))):
576578
return False

pandas/_testing.py

+55-41
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ def repr_class(x):
743743

744744

745745
def assert_attr_equal(attr, left, right, obj="Attributes"):
746-
"""checks attributes are equal. Both objects must have attribute.
746+
"""
747+
checks attributes are equal. Both objects must have attribute.
747748
748749
Parameters
749750
----------
@@ -820,7 +821,8 @@ def assert_is_sorted(seq):
820821
def assert_categorical_equal(
821822
left, right, check_dtype=True, check_category_order=True, obj="Categorical"
822823
):
823-
"""Test that Categoricals are equivalent.
824+
"""
825+
Test that Categoricals are equivalent.
824826
825827
Parameters
826828
----------
@@ -860,7 +862,8 @@ def assert_categorical_equal(
860862

861863

862864
def assert_interval_array_equal(left, right, exact="equiv", obj="IntervalArray"):
863-
"""Test that two IntervalArrays are equivalent.
865+
"""
866+
Test that two IntervalArrays are equivalent.
864867
865868
Parameters
866869
----------
@@ -1009,12 +1012,13 @@ def _raise(left, right, err_msg):
10091012
def assert_extension_array_equal(
10101013
left, right, check_dtype=True, check_less_precise=False, check_exact=False
10111014
):
1012-
"""Check that left and right ExtensionArrays are equal.
1015+
"""
1016+
Check that left and right ExtensionArrays are equal.
10131017
10141018
Parameters
10151019
----------
10161020
left, right : ExtensionArray
1017-
The two arrays to compare
1021+
The two arrays to compare.
10181022
check_dtype : bool, default True
10191023
Whether to check if the ExtensionArray dtypes are identical.
10201024
check_less_precise : bool or int, default False
@@ -1489,7 +1493,8 @@ def assert_sp_array_equal(
14891493
check_fill_value=True,
14901494
consolidate_block_indices=False,
14911495
):
1492-
"""Check that the left and right SparseArray are equal.
1496+
"""
1497+
Check that the left and right SparseArray are equal.
14931498
14941499
Parameters
14951500
----------
@@ -1724,7 +1729,8 @@ def _make_timeseries(start="2000-01-01", end="2000-12-31", freq="1D", seed=None)
17241729

17251730

17261731
def all_index_generator(k=10):
1727-
"""Generator which can be iterated over to get instances of all the various
1732+
"""
1733+
Generator which can be iterated over to get instances of all the various
17281734
index classes.
17291735
17301736
Parameters
@@ -1763,7 +1769,8 @@ def index_subclass_makers_generator():
17631769

17641770

17651771
def all_timeseries_index_generator(k=10):
1766-
"""Generator which can be iterated over to get instances of all the classes
1772+
"""
1773+
Generator which can be iterated over to get instances of all the classes
17671774
which represent time-series.
17681775
17691776
Parameters
@@ -1854,7 +1861,8 @@ def makePeriodFrame(nper=None):
18541861
def makeCustomIndex(
18551862
nentries, nlevels, prefix="#", names=False, ndupe_l=None, idx_type=None
18561863
):
1857-
"""Create an index/multindex with given dimensions, levels, names, etc'
1864+
"""
1865+
Create an index/multindex with given dimensions, levels, names, etc'
18581866
18591867
nentries - number of entries in index
18601868
nlevels - number of levels (> 1 produces multindex)
@@ -1970,35 +1978,39 @@ def makeCustomDataframe(
19701978
r_idx_type=None,
19711979
):
19721980
"""
1973-
nrows, ncols - number of data rows/cols
1974-
c_idx_names, idx_names - False/True/list of strings, yields No names ,
1975-
default names or uses the provided names for the levels of the
1976-
corresponding index. You can provide a single string when
1977-
c_idx_nlevels ==1.
1978-
c_idx_nlevels - number of levels in columns index. > 1 will yield MultiIndex
1979-
r_idx_nlevels - number of levels in rows index. > 1 will yield MultiIndex
1980-
data_gen_f - a function f(row,col) which return the data value
1981-
at that position, the default generator used yields values of the form
1982-
"RxCy" based on position.
1983-
c_ndupe_l, r_ndupe_l - list of integers, determines the number
1984-
of duplicates for each label at a given level of the corresponding
1985-
index. The default `None` value produces a multiplicity of 1 across
1986-
all levels, i.e. a unique index. Will accept a partial list of length
1987-
N < idx_nlevels, for just the first N levels. If ndupe doesn't divide
1988-
nrows/ncol, the last label might have lower multiplicity.
1989-
dtype - passed to the DataFrame constructor as is, in case you wish to
1990-
have more control in conjunction with a custom `data_gen_f`
1991-
r_idx_type, c_idx_type - "i"/"f"/"s"/"u"/"dt"/"td".
1992-
If idx_type is not None, `idx_nlevels` must be 1.
1993-
"i"/"f" creates an integer/float index,
1994-
"s"/"u" creates a string/unicode index
1995-
"dt" create a datetime index.
1996-
"td" create a timedelta index.
1981+
Create a DataFrame using supplied parameters.
19971982
1998-
if unspecified, string labels will be generated.
1999-
2000-
Examples:
1983+
Parameters
1984+
----------
1985+
nrows, ncols - number of data rows/cols
1986+
c_idx_names, idx_names - False/True/list of strings, yields No names ,
1987+
default names or uses the provided names for the levels of the
1988+
corresponding index. You can provide a single string when
1989+
c_idx_nlevels ==1.
1990+
c_idx_nlevels - number of levels in columns index. > 1 will yield MultiIndex
1991+
r_idx_nlevels - number of levels in rows index. > 1 will yield MultiIndex
1992+
data_gen_f - a function f(row,col) which return the data value
1993+
at that position, the default generator used yields values of the form
1994+
"RxCy" based on position.
1995+
c_ndupe_l, r_ndupe_l - list of integers, determines the number
1996+
of duplicates for each label at a given level of the corresponding
1997+
index. The default `None` value produces a multiplicity of 1 across
1998+
all levels, i.e. a unique index. Will accept a partial list of length
1999+
N < idx_nlevels, for just the first N levels. If ndupe doesn't divide
2000+
nrows/ncol, the last label might have lower multiplicity.
2001+
dtype - passed to the DataFrame constructor as is, in case you wish to
2002+
have more control in conjunction with a custom `data_gen_f`
2003+
r_idx_type, c_idx_type - "i"/"f"/"s"/"u"/"dt"/"td".
2004+
If idx_type is not None, `idx_nlevels` must be 1.
2005+
"i"/"f" creates an integer/float index,
2006+
"s"/"u" creates a string/unicode index
2007+
"dt" create a datetime index.
2008+
"td" create a timedelta index.
2009+
2010+
if unspecified, string labels will be generated.
20012011
2012+
Examples
2013+
--------
20022014
# 5 row, 3 columns, default names on both, single index on both axis
20032015
>> makeCustomDataframe(5,3)
20042016
@@ -2140,7 +2152,8 @@ def makeMissingDataframe(density=0.9, random_state=None):
21402152

21412153

21422154
def optional_args(decorator):
2143-
"""allows a decorator to take optional positional and keyword arguments.
2155+
"""
2156+
allows a decorator to take optional positional and keyword arguments.
21442157
Assumes that taking a single, callable, positional argument means that
21452158
it is decorating a function, i.e. something like this::
21462159
@@ -2212,7 +2225,8 @@ def _get_default_network_errors():
22122225

22132226

22142227
def can_connect(url, error_classes=None):
2215-
"""Try to connect to the given url. True if succeeds, False if IOError
2228+
"""
2229+
Try to connect to the given url. True if succeeds, False if IOError
22162230
raised
22172231
22182232
Parameters
@@ -2514,7 +2528,6 @@ class RNGContext:
25142528
25152529
Examples
25162530
--------
2517-
25182531
with RNGContext(42):
25192532
np.random.randn()
25202533
"""
@@ -2581,7 +2594,8 @@ def use_numexpr(use, min_elements=None):
25812594

25822595

25832596
def test_parallel(num_threads=2, kwargs_list=None):
2584-
"""Decorator to run the same function multiple times in parallel.
2597+
"""
2598+
Decorator to run the same function multiple times in parallel.
25852599
25862600
Parameters
25872601
----------
@@ -2590,6 +2604,7 @@ def test_parallel(num_threads=2, kwargs_list=None):
25902604
kwargs_list : list of dicts, optional
25912605
The list of kwargs to update original
25922606
function kwargs on different threads.
2607+
25932608
Notes
25942609
-----
25952610
This decorator does not pass the return value of the decorated function.
@@ -2669,7 +2684,6 @@ def set_timezone(tz: str):
26692684
26702685
Examples
26712686
--------
2672-
26732687
>>> from datetime import datetime
26742688
>>> from dateutil.tz import tzlocal
26752689
>>> tzlocal().tzname(datetime.now())

pandas/compat/chainmap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
class DeepChainMap(ChainMap[_KT, _VT]):
8-
"""Variant of ChainMap that allows direct updates to inner scopes.
8+
"""
9+
Variant of ChainMap that allows direct updates to inner scopes.
910
1011
Only works when all passed mapping are mutable.
1112
"""

pandas/conftest.py

+67
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas import DataFrame
1818
import pandas._testing as tm
1919
from pandas.core import ops
20+
from pandas.core.indexes.api import Index, MultiIndex
2021

2122
hypothesis.settings.register_profile(
2223
"ci",
@@ -982,3 +983,69 @@ def __len__(self):
982983
return self._data.__len__()
983984

984985
return TestNonDictMapping
986+
987+
988+
indices_dict = {
989+
"unicode": tm.makeUnicodeIndex(100),
990+
"string": tm.makeStringIndex(100),
991+
"datetime": tm.makeDateIndex(100),
992+
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
993+
"period": tm.makePeriodIndex(100),
994+
"timedelta": tm.makeTimedeltaIndex(100),
995+
"int": tm.makeIntIndex(100),
996+
"uint": tm.makeUIntIndex(100),
997+
"range": tm.makeRangeIndex(100),
998+
"float": tm.makeFloatIndex(100),
999+
"bool": tm.makeBoolIndex(2),
1000+
"categorical": tm.makeCategoricalIndex(100),
1001+
"interval": tm.makeIntervalIndex(100),
1002+
"empty": Index([]),
1003+
"tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])),
1004+
"repeats": Index([0, 0, 1, 1, 2, 2]),
1005+
}
1006+
1007+
1008+
@pytest.fixture(params=indices_dict.keys())
1009+
def indices(request):
1010+
# copy to avoid mutation, e.g. setting .name
1011+
return indices_dict[request.param].copy()
1012+
1013+
1014+
def _create_series(index):
1015+
""" Helper for the _series dict """
1016+
size = len(index)
1017+
data = np.random.randn(size)
1018+
return pd.Series(data, index=index, name="a")
1019+
1020+
1021+
_series = {
1022+
f"series-with-{index_id}-index": _create_series(index)
1023+
for index_id, index in indices_dict.items()
1024+
}
1025+
1026+
1027+
_narrow_dtypes = [
1028+
np.float16,
1029+
np.float32,
1030+
np.int8,
1031+
np.int16,
1032+
np.int32,
1033+
np.uint8,
1034+
np.uint16,
1035+
np.uint32,
1036+
]
1037+
_narrow_series = {
1038+
f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype)
1039+
for dtype in _narrow_dtypes
1040+
}
1041+
1042+
_index_or_series_objs = {**indices_dict, **_series, **_narrow_series}
1043+
1044+
1045+
@pytest.fixture(params=_index_or_series_objs.keys())
1046+
def index_or_series_obj(request):
1047+
"""
1048+
Fixture for tests on indexes, series and series with a narrow dtype
1049+
copy to avoid mutation, e.g. setting .name
1050+
"""
1051+
return _index_or_series_objs[request.param].copy(deep=True)

pandas/core/accessor.py

-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def __init__(self, pandas_object): # noqa: E999
233233
234234
Examples
235235
--------
236-
237236
In your library code::
238237
239238
import pandas as pd

pandas/core/aggregation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i
9898
def _make_unique_kwarg_list(
9999
seq: Sequence[Tuple[Any, Any]]
100100
) -> Sequence[Tuple[Any, Any]]:
101-
"""Uniquify aggfunc name of the pairs in the order list
101+
"""
102+
Uniquify aggfunc name of the pairs in the order list
102103
103104
Examples:
104105
--------

0 commit comments

Comments
 (0)