Skip to content

CLN: no need to broadcast axes for ndim<=2 (pytables) #30019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4232,21 +4232,7 @@ def write_data(self, chunksize: Optional[int], dropna: bool = False):
# broadcast the indexes if needed
indexes = [a.cvalues for a in self.index_axes]
nindexes = len(indexes)
bindexes = []
for i, idx in enumerate(indexes):

# broadcast to all other indexes except myself
if i > 0 and i < nindexes:
repeater = np.prod([indexes[bi].shape[0] for bi in range(0, i)])
idx = np.tile(idx, repeater)

if i < nindexes - 1:
repeater = np.prod(
[indexes[bi].shape[0] for bi in range(i + 1, nindexes)]
)
idx = np.repeat(idx, repeater)

bindexes.append(idx)
assert nindexes == 1, nindexes # ensures we dont need to broadcast

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

self.write_data_chunk(
rows,
indexes=[a[start_i:end_i] for a in bindexes],
indexes=[a[start_i:end_i] for a in indexes],
mask=mask[start_i:end_i] if mask is not None else None,
values=[v[start_i:end_i] for v in bvalues],
)
Expand Down