Skip to content

Commit b4bf49b

Browse files
committed
update stacklevel for doc decorator
2 parents d3dbe5d + 0fb892d commit b4bf49b

Some content is hidden

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

82 files changed

+939
-856
lines changed

ci/code_checks.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
150150
# Check for imports from pandas._testing instead of `import pandas._testing as tm`
151151
invgrep -R --include="*.py*" -E "from pandas._testing import" pandas/tests
152152
RET=$(($RET + $?)) ; echo $MSG "DONE"
153-
invgrep -R --include="*.py*" -E "from pandas.util import testing as tm" pandas/tests
153+
invgrep -R --include="*.py*" -E "from pandas import _testing as tm" pandas/tests
154+
RET=$(($RET + $?)) ; echo $MSG "DONE"
155+
156+
# No direct imports from conftest
157+
invgrep -R --include="*.py*" -E "conftest import" pandas/tests
158+
RET=$(($RET + $?)) ; echo $MSG "DONE"
159+
invgrep -R --include="*.py*" -E "import conftest" pandas/tests
154160
RET=$(($RET + $?)) ; echo $MSG "DONE"
155161

156162
MSG='Check for use of exec' ; echo $MSG

doc/source/getting_started/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ data set, a sliding window of the data or grouped by categories. The latter is a
398398
<div class="card-body">
399399

400400
Change the structure of your data table in multiple ways. You can :func:`~pandas.melt` your data table from wide to long/tidy form or :func:`~pandas.pivot`
401-
from long to wide format. With aggregations built-in, a pivot table is created with a sinlge command.
401+
from long to wide format. With aggregations built-in, a pivot table is created with a single command.
402402

403403
.. image:: ../_static/schemas/07_melt.svg
404404
:align: center

doc/source/user_guide/cookbook.rst

-27
Original file line numberDiff line numberDiff line change
@@ -1333,33 +1333,6 @@ Values can be set to NaT using np.nan, similar to datetime
13331333
y[1] = np.nan
13341334
y
13351335
1336-
Aliasing axis names
1337-
-------------------
1338-
1339-
To globally provide aliases for axis names, one can define these 2 functions:
1340-
1341-
.. ipython:: python
1342-
1343-
def set_axis_alias(cls, axis, alias):
1344-
if axis not in cls._AXIS_NUMBERS:
1345-
raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
1346-
cls._AXIS_ALIASES[alias] = axis
1347-
1348-
.. ipython:: python
1349-
1350-
def clear_axis_alias(cls, axis, alias):
1351-
if axis not in cls._AXIS_NUMBERS:
1352-
raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
1353-
cls._AXIS_ALIASES.pop(alias, None)
1354-
1355-
.. ipython:: python
1356-
1357-
set_axis_alias(pd.DataFrame, 'columns', 'myaxis2')
1358-
df2 = pd.DataFrame(np.random.randn(3, 2), columns=['c1', 'c2'],
1359-
index=['i1', 'i2', 'i3'])
1360-
df2.sum(axis='myaxis2')
1361-
clear_axis_alias(pd.DataFrame, 'columns', 'myaxis2')
1362-
13631336
Creating example data
13641337
---------------------
13651338

doc/source/whatsnew/v1.1.0.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,16 @@ Other API changes
175175
- :meth:`Groupby.groups` now returns an abbreviated representation when called on large dataframes (:issue:`1135`)
176176
- ``loc`` lookups with an object-dtype :class:`Index` and an integer key will now raise ``KeyError`` instead of ``TypeError`` when key is missing (:issue:`31905`)
177177
- Using a :func:`pandas.api.indexers.BaseIndexer` with ``skew``, ``cov``, ``corr`` will now raise a ``NotImplementedError`` (:issue:`32865`)
178-
- Using a :func:`pandas.api.indexers.BaseIndexer` with ``count``, ``min``, ``max`` will now return correct results for any monotonic :func:`pandas.api.indexers.BaseIndexer` descendant (:issue:`32865`)
178+
- Using a :func:`pandas.api.indexers.BaseIndexer` with ``count``, ``min``, ``max``, ``median`` will now return correct results for any monotonic :func:`pandas.api.indexers.BaseIndexer` descendant (:issue:`32865`)
179179
- Added a :func:`pandas.api.indexers.FixedForwardWindowIndexer` class to support forward-looking windows during ``rolling`` operations.
180180
-
181181

182182
Backwards incompatible API changes
183183
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184184
- :meth:`DataFrame.swaplevels` now raises a ``TypeError`` if the axis is not a :class:`MultiIndex`.
185-
Previously a ``AttributeError`` was raised (:issue:`31126`)
185+
Previously an ``AttributeError`` was raised (:issue:`31126`)
186+
- :meth:`DataFrame.xs` now raises a ``TypeError`` if a ``level`` keyword is supplied and the axis is not a :class:`MultiIndex`.
187+
Previously an ``AttributeError`` was raised (:issue:`33610`)
186188
- :meth:`DataFrameGroupby.mean` and :meth:`SeriesGroupby.mean` (and similarly for :meth:`~DataFrameGroupby.median`, :meth:`~DataFrameGroupby.std` and :meth:`~DataFrameGroupby.var`)
187189
now raise a ``TypeError`` if a not-accepted keyword argument is passed into it.
188190
Previously a ``UnsupportedFunctionCall`` was raised (``AssertionError`` if ``min_count`` passed into :meth:`~DataFrameGroupby.median`) (:issue:`31485`)
@@ -527,6 +529,7 @@ Indexing
527529
- Bug in :meth:`DataFrame.iloc` when slicing a single column-:class:`DataFrame`` with ``ExtensionDtype`` (e.g. ``df.iloc[:, :1]``) returning an invalid result (:issue:`32957`)
528530
- Bug in :meth:`DatetimeIndex.insert` and :meth:`TimedeltaIndex.insert` causing index ``freq`` to be lost when setting an element into an empty :class:`Series` (:issue:33573`)
529531
- Bug in :meth:`Series.__setitem__` with an :class:`IntervalIndex` and a list-like key of integers (:issue:`33473`)
532+
- Bug in :meth:`Series.__getitem__` allowing missing labels with ``np.ndarray``, :class:`Index`, :class:`Series` indexers but not ``list``, these now all raise ``KeyError`` (:issue:`33646`)
530533

531534
Missing
532535
^^^^^^^
@@ -580,6 +583,8 @@ I/O
580583
- Bug in :func:`pandas.io.json.json_normalize` where location specified by `record_path` doesn't point to an array. (:issue:`26284`)
581584
- :func:`pandas.read_hdf` has a more explicit error message when loading an
582585
unsupported HDF file (:issue:`9539`)
586+
- Bug in :meth:`~DataFrame.to_parquet` was not raising ``PermissionError`` when writing to a private s3 bucket with invalid creds. (:issue:`27679`)
587+
- Bug in :meth:`~DataFrame.to_csv` was silently failing when writing to an invalid s3 bucket. (:issue:`32486`)
583588

584589
Plotting
585590
^^^^^^^^

pandas/_libs/internals.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ cdef class BlockPlacement:
141141

142142
return BlockPlacement(val)
143143

144-
def delete(self, loc) -> "BlockPlacement":
144+
def delete(self, loc) -> BlockPlacement:
145145
return BlockPlacement(np.delete(self.as_array, loc, axis=0))
146146

147-
def append(self, others) -> "BlockPlacement":
147+
def append(self, others) -> BlockPlacement:
148148
if not len(others):
149149
return self
150150

@@ -185,7 +185,7 @@ cdef class BlockPlacement:
185185
val = newarr
186186
return BlockPlacement(val)
187187

188-
def add(self, other) -> "BlockPlacement":
188+
def add(self, other) -> BlockPlacement:
189189
# We can get here with int or ndarray
190190
return self.iadd(other)
191191

pandas/_libs/window/aggregations.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,8 @@ def roll_kurt_variable(ndarray[float64_t] values, ndarray[int64_t] start,
843843

844844

845845
def roll_median_c(ndarray[float64_t] values, ndarray[int64_t] start,
846-
ndarray[int64_t] end, int64_t minp, int64_t win):
846+
ndarray[int64_t] end, int64_t minp, int64_t win=0):
847+
# GH 32865. win argument kept for compatibility
847848
cdef:
848849
float64_t val, res, prev
849850
bint err = False
@@ -858,7 +859,7 @@ def roll_median_c(ndarray[float64_t] values, ndarray[int64_t] start,
858859
# actual skiplist ops outweigh any window computation costs
859860
output = np.empty(N, dtype=float)
860861

861-
if win == 0 or (end - start).max() == 0:
862+
if (end - start).max() == 0:
862863
output[:] = NaN
863864
return output
864865
win = (end - start).max()

pandas/_testing.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
import pandas._libs.testing as _testing
25-
from pandas._typing import FilePathOrBuffer, FrameOrSeries
25+
from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries
2626
from pandas.compat import _get_lzma_file, _import_lzma
2727

2828
from pandas.core.dtypes.common import (
@@ -73,6 +73,37 @@
7373
_K = 4
7474
_RAISE_NETWORK_ERROR_DEFAULT = False
7575

76+
UNSIGNED_INT_DTYPES: List[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
77+
UNSIGNED_EA_INT_DTYPES: List[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
78+
SIGNED_INT_DTYPES: List[Dtype] = [int, "int8", "int16", "int32", "int64"]
79+
SIGNED_EA_INT_DTYPES: List[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
80+
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
81+
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
82+
83+
FLOAT_DTYPES: List[Dtype] = [float, "float32", "float64"]
84+
COMPLEX_DTYPES: List[Dtype] = [complex, "complex64", "complex128"]
85+
STRING_DTYPES: List[Dtype] = [str, "str", "U"]
86+
87+
DATETIME64_DTYPES: List[Dtype] = ["datetime64[ns]", "M8[ns]"]
88+
TIMEDELTA64_DTYPES: List[Dtype] = ["timedelta64[ns]", "m8[ns]"]
89+
90+
BOOL_DTYPES = [bool, "bool"]
91+
BYTES_DTYPES = [bytes, "bytes"]
92+
OBJECT_DTYPES = [object, "object"]
93+
94+
ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
95+
ALL_NUMPY_DTYPES = (
96+
ALL_REAL_DTYPES
97+
+ COMPLEX_DTYPES
98+
+ STRING_DTYPES
99+
+ DATETIME64_DTYPES
100+
+ TIMEDELTA64_DTYPES
101+
+ BOOL_DTYPES
102+
+ OBJECT_DTYPES
103+
+ BYTES_DTYPES
104+
)
105+
106+
76107
# set testing_mode
77108
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)
78109

pandas/conftest.py

+13-47
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from decimal import Decimal
2424
import operator
2525
import os
26-
from typing import List
2726

2827
from dateutil.tz import tzlocal, tzutc
2928
import hypothesis
@@ -32,7 +31,6 @@
3231
import pytest
3332
from pytz import FixedOffset, utc
3433

35-
from pandas._typing import Dtype
3634
import pandas.util._test_decorators as td
3735

3836
import pandas as pd
@@ -864,39 +862,7 @@ def utc_fixture(request):
864862
# ----------------------------------------------------------------
865863
# Dtypes
866864
# ----------------------------------------------------------------
867-
868-
UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"]
869-
UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"]
870-
SIGNED_INT_DTYPES: List[Dtype] = [int, "int8", "int16", "int32", "int64"]
871-
SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"]
872-
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
873-
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
874-
875-
FLOAT_DTYPES: List[Dtype] = [float, "float32", "float64"]
876-
COMPLEX_DTYPES: List[Dtype] = [complex, "complex64", "complex128"]
877-
STRING_DTYPES: List[Dtype] = [str, "str", "U"]
878-
879-
DATETIME64_DTYPES = ["datetime64[ns]", "M8[ns]"]
880-
TIMEDELTA64_DTYPES = ["timedelta64[ns]", "m8[ns]"]
881-
882-
BOOL_DTYPES = [bool, "bool"]
883-
BYTES_DTYPES = [bytes, "bytes"]
884-
OBJECT_DTYPES = [object, "object"]
885-
886-
ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
887-
ALL_NUMPY_DTYPES = (
888-
ALL_REAL_DTYPES
889-
+ COMPLEX_DTYPES
890-
+ STRING_DTYPES
891-
+ DATETIME64_DTYPES
892-
+ TIMEDELTA64_DTYPES
893-
+ BOOL_DTYPES
894-
+ OBJECT_DTYPES
895-
+ BYTES_DTYPES
896-
)
897-
898-
899-
@pytest.fixture(params=STRING_DTYPES)
865+
@pytest.fixture(params=tm.STRING_DTYPES)
900866
def string_dtype(request):
901867
"""
902868
Parametrized fixture for string dtypes.
@@ -908,7 +874,7 @@ def string_dtype(request):
908874
return request.param
909875

910876

911-
@pytest.fixture(params=BYTES_DTYPES)
877+
@pytest.fixture(params=tm.BYTES_DTYPES)
912878
def bytes_dtype(request):
913879
"""
914880
Parametrized fixture for bytes dtypes.
@@ -919,7 +885,7 @@ def bytes_dtype(request):
919885
return request.param
920886

921887

922-
@pytest.fixture(params=OBJECT_DTYPES)
888+
@pytest.fixture(params=tm.OBJECT_DTYPES)
923889
def object_dtype(request):
924890
"""
925891
Parametrized fixture for object dtypes.
@@ -930,7 +896,7 @@ def object_dtype(request):
930896
return request.param
931897

932898

933-
@pytest.fixture(params=DATETIME64_DTYPES)
899+
@pytest.fixture(params=tm.DATETIME64_DTYPES)
934900
def datetime64_dtype(request):
935901
"""
936902
Parametrized fixture for datetime64 dtypes.
@@ -941,7 +907,7 @@ def datetime64_dtype(request):
941907
return request.param
942908

943909

944-
@pytest.fixture(params=TIMEDELTA64_DTYPES)
910+
@pytest.fixture(params=tm.TIMEDELTA64_DTYPES)
945911
def timedelta64_dtype(request):
946912
"""
947913
Parametrized fixture for timedelta64 dtypes.
@@ -952,7 +918,7 @@ def timedelta64_dtype(request):
952918
return request.param
953919

954920

955-
@pytest.fixture(params=FLOAT_DTYPES)
921+
@pytest.fixture(params=tm.FLOAT_DTYPES)
956922
def float_dtype(request):
957923
"""
958924
Parameterized fixture for float dtypes.
@@ -964,7 +930,7 @@ def float_dtype(request):
964930
return request.param
965931

966932

967-
@pytest.fixture(params=COMPLEX_DTYPES)
933+
@pytest.fixture(params=tm.COMPLEX_DTYPES)
968934
def complex_dtype(request):
969935
"""
970936
Parameterized fixture for complex dtypes.
@@ -976,7 +942,7 @@ def complex_dtype(request):
976942
return request.param
977943

978944

979-
@pytest.fixture(params=SIGNED_INT_DTYPES)
945+
@pytest.fixture(params=tm.SIGNED_INT_DTYPES)
980946
def sint_dtype(request):
981947
"""
982948
Parameterized fixture for signed integer dtypes.
@@ -990,7 +956,7 @@ def sint_dtype(request):
990956
return request.param
991957

992958

993-
@pytest.fixture(params=UNSIGNED_INT_DTYPES)
959+
@pytest.fixture(params=tm.UNSIGNED_INT_DTYPES)
994960
def uint_dtype(request):
995961
"""
996962
Parameterized fixture for unsigned integer dtypes.
@@ -1003,7 +969,7 @@ def uint_dtype(request):
1003969
return request.param
1004970

1005971

1006-
@pytest.fixture(params=ALL_INT_DTYPES)
972+
@pytest.fixture(params=tm.ALL_INT_DTYPES)
1007973
def any_int_dtype(request):
1008974
"""
1009975
Parameterized fixture for any integer dtype.
@@ -1021,7 +987,7 @@ def any_int_dtype(request):
1021987
return request.param
1022988

1023989

1024-
@pytest.fixture(params=ALL_EA_INT_DTYPES)
990+
@pytest.fixture(params=tm.ALL_EA_INT_DTYPES)
1025991
def any_nullable_int_dtype(request):
1026992
"""
1027993
Parameterized fixture for any nullable integer dtype.
@@ -1038,7 +1004,7 @@ def any_nullable_int_dtype(request):
10381004
return request.param
10391005

10401006

1041-
@pytest.fixture(params=ALL_REAL_DTYPES)
1007+
@pytest.fixture(params=tm.ALL_REAL_DTYPES)
10421008
def any_real_dtype(request):
10431009
"""
10441010
Parameterized fixture for any (purely) real numeric dtype.
@@ -1059,7 +1025,7 @@ def any_real_dtype(request):
10591025
return request.param
10601026

10611027

1062-
@pytest.fixture(params=ALL_NUMPY_DTYPES)
1028+
@pytest.fixture(params=tm.ALL_NUMPY_DTYPES)
10631029
def any_numpy_dtype(request):
10641030
"""
10651031
Parameterized fixture for all numpy dtypes.

pandas/core/array_algos/transforms.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
def shift(values: np.ndarray, periods: int, axis: int, fill_value) -> np.ndarray:
1111
new_values = values
1212

13+
if periods == 0:
14+
# TODO: should we copy here?
15+
return new_values
16+
1317
# make sure array sent to np.roll is c_contiguous
1418
f_ordered = values.flags.f_contiguous
1519
if f_ordered:

0 commit comments

Comments
 (0)