Skip to content

Commit 1fc4320

Browse files
jbrockmendeljreback
authored andcommitted
CLN: no need to broadcast axes for ndim<=2 (#30019)
1 parent 295c9c0 commit 1fc4320

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

pandas/io/pytables.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -4232,21 +4232,7 @@ def write_data(self, chunksize: Optional[int], dropna: bool = False):
42324232
# broadcast the indexes if needed
42334233
indexes = [a.cvalues for a in self.index_axes]
42344234
nindexes = len(indexes)
4235-
bindexes = []
4236-
for i, idx in enumerate(indexes):
4237-
4238-
# broadcast to all other indexes except myself
4239-
if i > 0 and i < nindexes:
4240-
repeater = np.prod([indexes[bi].shape[0] for bi in range(0, i)])
4241-
idx = np.tile(idx, repeater)
4242-
4243-
if i < nindexes - 1:
4244-
repeater = np.prod(
4245-
[indexes[bi].shape[0] for bi in range(i + 1, nindexes)]
4246-
)
4247-
idx = np.repeat(idx, repeater)
4248-
4249-
bindexes.append(idx)
4235+
assert nindexes == 1, nindexes # ensures we dont need to broadcast
42504236

42514237
# transpose the values so first dimension is last
42524238
# reshape the values if needed
@@ -4271,7 +4257,7 @@ def write_data(self, chunksize: Optional[int], dropna: bool = False):
42714257

42724258
self.write_data_chunk(
42734259
rows,
4274-
indexes=[a[start_i:end_i] for a in bindexes],
4260+
indexes=[a[start_i:end_i] for a in indexes],
42754261
mask=mask[start_i:end_i] if mask is not None else None,
42764262
values=[v[start_i:end_i] for v in bvalues],
42774263
)

0 commit comments

Comments
 (0)