Skip to content

Commit 164e716

Browse files
authored
Merge branch 'main' into issue_61889
2 parents 359f74e + 073710f commit 164e716

File tree

11 files changed

+48
-23
lines changed

11 files changed

+48
-23
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
LANG: ${{ matrix.lang || 'C.UTF-8' }}
9292
LC_ALL: ${{ matrix.lc_all || '' }}
9393
PANDAS_CI: '1'
94-
PANDAS_FUTURE_INFER_STRING: ${{ matrix.pandas_future_infer_string || '0' }}
94+
PANDAS_FUTURE_INFER_STRING: ${{ matrix.pandas_future_infer_string || '1' }}
9595
TEST_ARGS: ${{ matrix.test_args || '' }}
9696
PYTEST_WORKERS: 'auto'
9797
PYTEST_TARGET: ${{ matrix.pytest_target || 'pandas' }}

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ Other Deprecations
457457
- Deprecated :meth:`.DataFrameGroupby.corrwith` (:issue:`57158`)
458458
- Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`)
459459
- Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`)
460+
- Deprecated ``pd.core.internals.api.maybe_infer_ndim`` (:issue:`40226`)
460461
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.all`, :meth:`DataFrame.min`, :meth:`DataFrame.max`, :meth:`DataFrame.sum`, :meth:`DataFrame.prod`, :meth:`DataFrame.mean`, :meth:`DataFrame.median`, :meth:`DataFrame.sem`, :meth:`DataFrame.var`, :meth:`DataFrame.std`, :meth:`DataFrame.skew`, :meth:`DataFrame.kurt`, :meth:`Series.all`, :meth:`Series.min`, :meth:`Series.max`, :meth:`Series.sum`, :meth:`Series.prod`, :meth:`Series.mean`, :meth:`Series.median`, :meth:`Series.sem`, :meth:`Series.var`, :meth:`Series.std`, :meth:`Series.skew`, and :meth:`Series.kurt`. (:issue:`57087`)
461462
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
462463
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)

pandas/_libs/internals.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,9 @@ cdef class Block:
709709
self.ndim = state[2]
710710
else:
711711
# older pickle
712-
from pandas.core.internals.api import maybe_infer_ndim
712+
from pandas.core.internals.api import _maybe_infer_ndim
713713

714-
ndim = maybe_infer_ndim(self.values, self.mgr_locs)
714+
ndim = _maybe_infer_ndim(self.values, self.mgr_locs)
715715
self.ndim = ndim
716716

717717
cpdef Block slice_block_rows(self, slice slicer):

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
17781778
>>> rng.strftime("%%B %%d, %%Y, %%r")
17791779
Index(['March 10, 2018, 09:00:00 AM', 'March 10, 2018, 09:00:01 AM',
17801780
'March 10, 2018, 09:00:02 AM'],
1781-
dtype='object')
1781+
dtype='str')
17821782
"""
17831783
result = self._format_native_types(date_format=date_format, na_rep=np.nan)
17841784
if using_string_dtype():

pandas/core/arrays/datetimes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,14 +1308,14 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]:
13081308
0 January
13091309
1 February
13101310
2 March
1311-
dtype: object
1311+
dtype: str
13121312
13131313
>>> idx = pd.date_range(start="2018-01", freq="ME", periods=3)
13141314
>>> idx
13151315
DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'],
13161316
dtype='datetime64[ns]', freq='ME')
13171317
>>> idx.month_name()
1318-
Index(['January', 'February', 'March'], dtype='object')
1318+
Index(['January', 'February', 'March'], dtype='str')
13191319
13201320
Using the ``locale`` parameter you can set a different locale language,
13211321
for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month
@@ -1326,7 +1326,7 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]:
13261326
DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'],
13271327
dtype='datetime64[ns]', freq='ME')
13281328
>>> idx.month_name(locale="pt_BR.utf8") # doctest: +SKIP
1329-
Index(['Janeiro', 'Fevereiro', 'Março'], dtype='object')
1329+
Index(['Janeiro', 'Fevereiro', 'Março'], dtype='str')
13301330
"""
13311331
values = self._local_timestamps()
13321332

@@ -1376,14 +1376,14 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]:
13761376
0 Monday
13771377
1 Tuesday
13781378
2 Wednesday
1379-
dtype: object
1379+
dtype: str
13801380
13811381
>>> idx = pd.date_range(start="2018-01-01", freq="D", periods=3)
13821382
>>> idx
13831383
DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'],
13841384
dtype='datetime64[ns]', freq='D')
13851385
>>> idx.day_name()
1386-
Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
1386+
Index(['Monday', 'Tuesday', 'Wednesday'], dtype='str')
13871387
13881388
Using the ``locale`` parameter you can set a different locale language,
13891389
for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day
@@ -1394,7 +1394,7 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]:
13941394
DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'],
13951395
dtype='datetime64[ns]', freq='D')
13961396
>>> idx.day_name(locale="pt_BR.utf8") # doctest: +SKIP
1397-
Index(['Segunda', 'Terça', 'Quarta'], dtype='object')
1397+
Index(['Segunda', 'Terça', 'Quarta'], dtype='str')
13981398
"""
13991399
values = self._local_timestamps()
14001400

pandas/core/generic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ def keys(self) -> Index:
19181918
b 2 4
19191919
c 3 8
19201920
>>> d.keys()
1921-
Index(['A', 'B'], dtype='object')
1921+
Index(['A', 'B'], dtype='str')
19221922
"""
19231923
return self._info_axis
19241924

@@ -6276,7 +6276,7 @@ def dtypes(self):
62766276
float float64
62776277
int int64
62786278
datetime datetime64[s]
6279-
string object
6279+
string str
62806280
dtype: object
62816281
"""
62826282
data = self._mgr.get_dtypes()
@@ -6838,7 +6838,7 @@ def convert_dtypes(
68386838
0 a
68396839
1 b
68406840
2 NaN
6841-
dtype: object
6841+
dtype: str
68426842
68436843
Obtain a Series with dtype ``StringDtype``.
68446844
@@ -8138,7 +8138,7 @@ def isna(self) -> Self:
81388138
... )
81398139
>>> df
81408140
age born name toy
8141-
0 5.0 NaT Alfred None
8141+
0 5.0 NaT Alfred NaN
81428142
1 6.0 1939-05-27 Batman Batmobile
81438143
2 NaN 1940-04-25 Joker
81448144
@@ -8211,7 +8211,7 @@ def notna(self) -> Self:
82118211
... )
82128212
>>> df
82138213
age born name toy
8214-
0 5.0 NaT Alfred None
8214+
0 5.0 NaT Alfred NaN
82158215
1 6.0 1939-05-27 Batman Batmobile
82168216
2 NaN 1940-04-25 Joker
82178217
@@ -10401,7 +10401,7 @@ def truncate(
1040110401
2 b
1040210402
3 c
1040310403
4 d
10404-
Name: A, dtype: object
10404+
Name: A, dtype: str
1040510405
1040610406
The index values in ``truncate`` can be datetimes or string
1040710407
dates.

pandas/core/indexes/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def astype(self, dtype: Dtype, copy: bool = True):
12091209
--------
12101210
>>> idx = pd.Index(['a', 'b', 'c'])
12111211
>>> idx.take([2, 2, 1, 2])
1212-
Index(['c', 'c', 'b', 'c'], dtype='object')
1212+
Index(['c', 'c', 'b', 'c'], dtype='str')
12131213
"""
12141214

12151215
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
@@ -6862,11 +6862,11 @@ def delete(
68626862
--------
68636863
>>> idx = pd.Index(["a", "b", "c"])
68646864
>>> idx.delete(1)
6865-
Index(['a', 'c'], dtype='object')
6865+
Index(['a', 'c'], dtype='str')
68666866
68676867
>>> idx = pd.Index(["a", "b", "c"])
68686868
>>> idx.delete([0, 2])
6869-
Index(['b'], dtype='object')
6869+
Index(['b'], dtype='str')
68706870
"""
68716871
values = self._values
68726872
res_values: ArrayLike
@@ -6906,7 +6906,7 @@ def insert(self, loc: int, item) -> Index:
69066906
--------
69076907
>>> idx = pd.Index(["a", "b", "c"])
69086908
>>> idx.insert(1, "x")
6909-
Index(['a', 'x', 'b', 'c'], dtype='object')
6909+
Index(['a', 'x', 'b', 'c'], dtype='str')
69106910
"""
69116911
item = lib.item_from_zerodim(item)
69126912
if is_valid_na_for_dtype(item, self.dtype) and self.dtype != object:

pandas/core/internals/api.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def make_block(
136136
if not isinstance(placement, BlockPlacement):
137137
placement = BlockPlacement(placement)
138138

139-
ndim = maybe_infer_ndim(values, placement, ndim)
139+
ndim = _maybe_infer_ndim(values, placement, ndim)
140140
if isinstance(values.dtype, (PeriodDtype, DatetimeTZDtype)):
141141
# GH#41168 ensure we can pass 1D dt64tz values
142142
# More generally, any EA dtype that isn't is_1d_only_ea_dtype
@@ -148,7 +148,7 @@ def make_block(
148148
return klass(values, ndim=ndim, placement=placement)
149149

150150

151-
def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
151+
def _maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
152152
"""
153153
If `ndim` is not provided, infer it from placement and values.
154154
"""
@@ -162,3 +162,15 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int
162162
else:
163163
ndim = values.ndim
164164
return ndim
165+
166+
167+
def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
168+
"""
169+
If `ndim` is not provided, infer it from placement and values.
170+
"""
171+
warnings.warn(
172+
"maybe_infer_ndim is deprecated and will be removed in a future version.",
173+
DeprecationWarning,
174+
stacklevel=2,
175+
)
176+
return _maybe_infer_ndim(values, placement, ndim)

pandas/tests/indexing/test_iloc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pytest
88

9+
from pandas.compat import pa_version_under16p0
910
from pandas.errors import IndexingError
1011

1112
from pandas import (
@@ -140,6 +141,9 @@ def test_is_scalar_access(self):
140141
df = ser.to_frame()
141142
assert df.iloc._is_scalar_access((1, 0))
142143

144+
@pytest.mark.skipif(
145+
pa_version_under16p0, reason="https://github.com/apache/arrow/issues/40642"
146+
)
143147
def test_iloc_exceeds_bounds(self):
144148
# GH6296
145149
# iloc should allow indexers that exceed the bounds

pandas/tests/internals/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def test_create_block_manager_from_blocks_deprecated():
7979
internals.create_block_manager_from_blocks
8080

8181

82+
def test_maybe_infer_ndim_deprecated():
83+
# GH#40226
84+
msg = "maybe_infer_ndim is deprecated and will be removed in a future version."
85+
arr = np.arange(5)
86+
bp = pd._libs.internals.BlockPlacement([1])
87+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
88+
internals.api.maybe_infer_ndim(arr, bp, 1)
89+
90+
8291
def test_create_dataframe_from_blocks(float_frame):
8392
block = float_frame._mgr.blocks[0]
8493
index = float_frame.index.copy()

0 commit comments

Comments
 (0)