Skip to content

Commit d49552d

Browse files
committed
concat notes
1 parent 9131eaf commit d49552d

File tree

22 files changed

+57
-51
lines changed

22 files changed

+57
-51
lines changed

pandas/core/apply.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def transform_dict_like(self, func) -> DataFrame:
382382
for name, how in func.items():
383383
colg = obj._gotitem(name, ndim=1)
384384
results[name] = colg.transform(how, 0, *args, **kwargs)
385-
return concat(results, axis=1)
385+
return concat(results, axis=1) # nobug
386386

387387
def transform_str_or_callable(self, func) -> DataFrame | Series:
388388
"""
@@ -485,7 +485,7 @@ def wrap_results_list_like(
485485
obj = self.obj
486486

487487
try:
488-
return concat(results, keys=keys, axis=1, sort=False)
488+
return concat(results, keys=keys, axis=1, sort=False) # maybebug
489489
except TypeError as err:
490490
# we are concatting non-NDFrame objects,
491491
# e.g. a list of scalars
@@ -635,7 +635,7 @@ def wrap_results_dict_like(
635635
keys_to_use = ktu
636636

637637
axis: AxisInt = 0 if isinstance(obj, ABCSeries) else 1
638-
result = concat(
638+
result = concat( # maybebug
639639
results,
640640
axis=axis,
641641
keys=keys_to_use,

pandas/core/arrays/arrow/accessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,6 @@ def explode(self) -> DataFrame:
496496
from pandas import concat
497497

498498
pa_type = self._pa_array.type
499-
return concat(
499+
return concat( # nobug
500500
[self.field(i) for i in range(pa_type.num_fields)], axis="columns"
501501
)

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ def describe(self) -> DataFrame:
26902690
from pandas import Index
26912691
from pandas.core.reshape.concat import concat
26922692

2693-
result = concat([counts, freqs], ignore_index=True, axis=1)
2693+
result = concat([counts, freqs], ignore_index=True, axis=1) # nobug
26942694
result.columns = Index(["counts", "freqs"])
26952695
result.index.name = "categories"
26962696

pandas/core/frame.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6130,7 +6130,7 @@ def shift(
61306130
.shift(periods=period, freq=freq, axis=axis, fill_value=fill_value)
61316131
.add_suffix(f"{suffix}_{period}" if suffix else f"_{period}")
61326132
)
6133-
return concat(shifted_dataframes, axis=1)
6133+
return concat(shifted_dataframes, axis=1) # bug
61346134
elif suffix:
61356135
raise ValueError("Cannot specify `suffix` if `periods` is an int.")
61366136
periods = cast(int, periods)
@@ -11168,7 +11168,7 @@ def _append_internal(
1116811168

1116911169
from pandas.core.reshape.concat import concat
1117011170

11171-
result = concat(
11171+
result = concat( # possible bug
1117211172
[self, row_df],
1117311173
ignore_index=ignore_index,
1117411174
)
@@ -11396,12 +11396,12 @@ def join(
1139611396
# join indexes only using concat
1139711397
if can_concat:
1139811398
if how == "left":
11399-
res = concat(
11399+
res = concat( # nobug
1140011400
frames, axis=1, join="outer", verify_integrity=True, sort=sort
1140111401
)
1140211402
return res.reindex(self.index)
1140311403
else:
11404-
return concat(
11404+
return concat( # bug
1140511405
frames, axis=1, join=how, verify_integrity=True, sort=sort
1140611406
)
1140711407

@@ -11590,7 +11590,9 @@ def _series_round(ser: Series, decimals: int) -> Series:
1159011590

1159111591
if new_cols is not None and len(new_cols) > 0:
1159211592
return self._constructor(
11593-
concat(new_cols, axis=1), index=self.index, columns=self.columns
11593+
concat(new_cols, axis=1),
11594+
index=self.index,
11595+
columns=self.columns, # nobug
1159411596
).__finalize__(self, method="round")
1159511597
else:
1159611598
return self.copy(deep=False)
@@ -14173,7 +14175,7 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
1417314175
from pandas.core.reshape.concat import concat
1417414176

1417514177
values = collections.defaultdict(list, values)
14176-
result = concat(
14178+
result = concat( # nobug
1417714179
(
1417814180
self.iloc[:, [i]].isin(values[col])
1417914181
for i, col in enumerate(self.columns)

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6525,7 +6525,7 @@ def astype(
65256525
return self.copy(deep=False)
65266526

65276527
# GH 19920: retain column metadata after concat
6528-
result = concat(results, axis=1)
6528+
result = concat(results, axis=1) # nobug
65296529
# GH#40810 retain subclass
65306530
# error: Incompatible types in assignment
65316531
# (expression has type "Self", variable has type "DataFrame")
@@ -9507,7 +9507,7 @@ def compare(
95079507

95089508
# error: List item 0 has incompatible type "NDFrame"; expected
95099509
# "Union[Series, DataFrame]"
9510-
diff = concat(
9510+
diff = concat( # bug
95119511
[self, other], # type: ignore[list-item]
95129512
axis=axis,
95139513
keys=result_names,

pandas/core/groupby/generic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def _aggregate_multiple_funcs(self, arg, *args, **kwargs) -> DataFrame:
549549
if any(isinstance(x, DataFrame) for x in results.values()):
550550
from pandas import concat
551551

552-
res_df = concat(
552+
res_df = concat( # nobug
553553
results.values(), axis=1, keys=[key.label for key in results]
554554
)
555555
return res_df
@@ -722,7 +722,7 @@ def _transform_general(
722722
if results:
723723
from pandas.core.reshape.concat import concat
724724

725-
concatenated = concat(results, ignore_index=True)
725+
concatenated = concat(results, ignore_index=True) # nobug
726726
result = self._set_result_index_ordered(concatenated)
727727
else:
728728
result = self.obj._constructor(dtype=np.float64)
@@ -2238,7 +2238,7 @@ def _transform_general(self, func, engine, engine_kwargs, *args, **kwargs):
22382238
applied.append(res)
22392239

22402240
concat_index = obj.columns
2241-
concatenated = concat(
2241+
concatenated = concat( # nobug
22422242
applied, axis=0, verify_integrity=False, ignore_index=True
22432243
)
22442244
concatenated = concatenated.reindex(concat_index, axis=1)
@@ -2530,7 +2530,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
25302530
# concat would raise
25312531
res_df = DataFrame([], columns=columns, index=self._grouper.result_index)
25322532
else:
2533-
res_df = concat(results, keys=columns, axis=1)
2533+
res_df = concat(results, keys=columns, axis=1) # nobug
25342534

25352535
if not self.as_index:
25362536
res_df.index = default_index(len(res_df))
@@ -3390,7 +3390,9 @@ def _wrap_transform_general_frame(
33903390
# other dimension; this will preserve dtypes
33913391
# GH14457
33923392
if res.index.is_(obj.index):
3393-
res_frame = concat([res] * len(group.columns), axis=1, ignore_index=True)
3393+
res_frame = concat(
3394+
[res] * len(group.columns), axis=1, ignore_index=True
3395+
) # nobug
33943396
res_frame.columns = group.columns
33953397
res_frame.index = group.index
33963398
else:

pandas/core/groupby/groupby.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def _concat_objects(
11431143
group_levels = self._grouper.levels
11441144
group_names = self._grouper.names
11451145

1146-
result = concat(
1146+
result = concat( # maybebug
11471147
values,
11481148
axis=0,
11491149
keys=group_keys,
@@ -1152,10 +1152,10 @@ def _concat_objects(
11521152
sort=False,
11531153
)
11541154
else:
1155-
result = concat(values, axis=0)
1155+
result = concat(values, axis=0) # maybebug
11561156

11571157
elif not not_indexed_same:
1158-
result = concat(values, axis=0)
1158+
result = concat(values, axis=0) # maybebug
11591159

11601160
ax = self._selected_obj.index
11611161
if self.dropna:
@@ -1178,7 +1178,7 @@ def _concat_objects(
11781178
result = result.reindex(ax, axis=0)
11791179

11801180
else:
1181-
result = concat(values, axis=0)
1181+
result = concat(values, axis=0) # maybebug
11821182

11831183
if self.obj.ndim == 1:
11841184
name = self.obj.name
@@ -5238,7 +5238,7 @@ def shift(
52385238
return (
52395239
shifted_dataframes[0]
52405240
if len(shifted_dataframes) == 1
5241-
else concat(shifted_dataframes, axis=1, sort=False)
5241+
else concat(shifted_dataframes, axis=1, sort=False) # nobug
52425242
)
52435243

52445244
@final

pandas/core/indexes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,9 +5379,9 @@ def append(self, other: Index | Sequence[Index]) -> Index:
53795379
names = {obj.name for obj in to_concat}
53805380
name = None if len(names) > 1 else self.name
53815381

5382-
return self._concat(to_concat, name)
5382+
return self._concat(to_concat, name) # nobug
53835383

5384-
def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
5384+
def _concat(self, to_concat: list[Index], name: Hashable) -> Index: # nobug
53855385
"""
53865386
Concatenate multiple Index objects.
53875387
"""

pandas/core/indexes/range.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ def insert(self, loc: int, item) -> Index:
11811181

11821182
return super().insert(loc, item)
11831183

1184-
def _concat(self, indexes: list[Index], name: Hashable) -> Index:
1184+
def _concat(self, indexes: list[Index], name: Hashable) -> Index: # nobug
11851185
"""
11861186
Overriding parent method for the case of all RangeIndex instances.
11871187
@@ -1191,7 +1191,7 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
11911191
indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Index([0,1,2,4,5], dtype='int64')
11921192
"""
11931193
if not all(isinstance(x, RangeIndex) for x in indexes):
1194-
result = super()._concat(indexes, name)
1194+
result = super()._concat(indexes, name) # nobug
11951195
if result.dtype.kind == "i":
11961196
return self._shallow_copy(result._values)
11971197
return result

pandas/core/interchange/from_dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _from_dataframe(df: DataFrameXchg, allow_copy: bool = True) -> pd.DataFrame:
144144
elif len(pandas_dfs) == 1:
145145
pandas_df = pandas_dfs[0]
146146
else:
147-
pandas_df = pd.concat(pandas_dfs, axis=0, ignore_index=True, copy=False)
147+
pandas_df = pd.concat(pandas_dfs, axis=0, ignore_index=True, copy=False) # bug
148148

149149
index_obj = df.metadata.get("pandas.index", None)
150150
if index_obj is not None:

0 commit comments

Comments
 (0)