Skip to content

Commit fc29d9b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into ref/index_equiv
2 parents bbcc280 + ec3eddd commit fc29d9b

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

.github/workflows/wheels.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ jobs:
139139
shell: bash -el {0}
140140
run: echo "sdist_name=$(cd ./dist && ls -d */)" >> "$GITHUB_ENV"
141141

142-
- name: Build normal wheels
143-
if: ${{ (env.IS_SCHEDULE_DISPATCH != 'true' || env.IS_PUSH == 'true') }}
142+
- name: Build wheels
144143
uses: pypa/[email protected]
145144
with:
146145
package-dir: ./dist/${{ startsWith(matrix.buildplat[1], 'macosx') && env.sdist_name || needs.build_sdist.outputs.sdist_file }}

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ Performance improvements
297297
~~~~~~~~~~~~~~~~~~~~~~~~
298298
- :attr:`Categorical.categories` returns a :class:`RangeIndex` columns instead of an :class:`Index` if the constructed ``values`` was a ``range``. (:issue:`57787`)
299299
- :class:`DataFrame` returns a :class:`RangeIndex` columns when possible when ``data`` is a ``dict`` (:issue:`57943`)
300+
- :class:`Series` returns a :class:`RangeIndex` index when possible when ``data`` is a ``dict`` (:issue:`58118`)
301+
- :func:`concat` returns a :class:`RangeIndex` column when possible when ``objs`` contains :class:`Series` and :class:`DataFrame` and ``axis=0`` (:issue:`58119`)
300302
- :func:`concat` returns a :class:`RangeIndex` level in the :class:`MultiIndex` result when ``keys`` is a ``range`` or :class:`RangeIndex` (:issue:`57542`)
301303
- :meth:`RangeIndex.append` returns a :class:`RangeIndex` instead of a :class:`Index` when appending values that could continue the :class:`RangeIndex` (:issue:`57467`)
302304
- :meth:`Series.str.extract` returns a :class:`RangeIndex` columns instead of an :class:`Index` column when possible (:issue:`57542`)

pandas/core/indexes/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6453,6 +6453,10 @@ def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
64536453
>>> idx = pd.Index(list("abcd"))
64546454
>>> idx.slice_locs(start="b", end="c")
64556455
(1, 3)
6456+
6457+
>>> idx = pd.Index(list("bcde"))
6458+
>>> idx.slice_locs(start="a", end="c")
6459+
(0, 2)
64566460
"""
64576461
inc = step is None or step >= 0
64586462

@@ -7144,7 +7148,10 @@ def maybe_sequence_to_range(sequence) -> Any | range:
71447148
return sequence
71457149
if len(sequence) == 0:
71467150
return range(0)
7147-
np_sequence = np.asarray(sequence, dtype=np.int64)
7151+
try:
7152+
np_sequence = np.asarray(sequence, dtype=np.int64)
7153+
except OverflowError:
7154+
return sequence
71487155
diff = np_sequence[1] - np_sequence[0]
71497156
if diff == 0:
71507157
return sequence

pandas/core/reshape/concat.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,11 @@ def _sanitize_mixed_ndim(
518518
# to have unique names
519519
name = current_column
520520
current_column += 1
521-
522-
obj = sample._constructor({name: obj}, copy=False)
521+
obj = sample._constructor(obj, copy=False)
522+
if isinstance(obj, ABCDataFrame):
523+
obj.columns = range(name, name + 1, 1)
524+
else:
525+
obj = sample._constructor({name: obj}, copy=False)
523526

524527
new_objs.append(obj)
525528

pandas/core/series.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
PeriodIndex,
133133
default_index,
134134
ensure_index,
135+
maybe_sequence_to_range,
135136
)
136137
import pandas.core.indexes.base as ibase
137138
from pandas.core.indexes.multi import maybe_droplevels
@@ -538,16 +539,14 @@ def _init_dict(
538539
_data : BlockManager for the new Series
539540
index : index for the new Series
540541
"""
541-
keys: Index | tuple
542-
543542
# Looking for NaN in dict doesn't work ({np.nan : 1}[float('nan')]
544543
# raises KeyError), so we iterate the entire dict, and align
545544
if data:
546545
# GH:34717, issue was using zip to extract key and values from data.
547546
# using generators in effects the performance.
548547
# Below is the new way of extracting the keys and values
549548

550-
keys = tuple(data.keys())
549+
keys = maybe_sequence_to_range(tuple(data.keys()))
551550
values = list(data.values()) # Generating list of values- faster way
552551
elif index is not None:
553552
# fastpath for Series(data=None). Just use broadcasting a scalar

pandas/tests/reshape/concat/test_concat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,3 +912,11 @@ def test_concat_none_with_timezone_timestamp():
912912
result = concat([df1, df2], ignore_index=True)
913913
expected = DataFrame({"A": [None, pd.Timestamp("1990-12-20 00:00:00+00:00")]})
914914
tm.assert_frame_equal(result, expected)
915+
916+
917+
def test_concat_with_series_and_frame_returns_rangeindex_columns():
918+
ser = Series([0])
919+
df = DataFrame([1, 2])
920+
result = concat([ser, df])
921+
expected = DataFrame([0, 1, 2], index=[0, 0, 1])
922+
tm.assert_frame_equal(result, expected, check_column_type=True)

pandas/tests/series/test_constructors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,3 +2251,9 @@ def test_series_with_complex_nan(input_list):
22512251
result = Series(ser.array)
22522252
assert ser.dtype == "complex128"
22532253
tm.assert_series_equal(ser, result)
2254+
2255+
2256+
def test_dict_keys_rangeindex():
2257+
result = Series({0: 1, 1: 2})
2258+
expected = Series([1, 2], index=RangeIndex(2))
2259+
tm.assert_series_equal(result, expected, check_index_type=True)

0 commit comments

Comments
 (0)