-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
[ArrayManager] Implement concat with axis=1 (merge/join) #39841
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
[ArrayManager] Implement concat with axis=1 (merge/join) #39841
Conversation
@@ -153,6 +153,7 @@ jobs: | |||
run: | | |||
source activate pandas-dev | |||
pytest pandas/tests/frame/methods --array-manager | |||
pytest pandas/tests/reshape/merge --array-manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only reshape/merge
and not reshape/concat
, as there are too many tests still failing in the concat tests (because axis=0 is not yet handled properly)
pandas/core/internals/concat.py
Outdated
mgrs.append(mgr) | ||
|
||
# concatting along the rows -> concat the reindexed arrays | ||
# TODO(ArrayManager) doesn't yet preserve the correct dtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this comment apply to both cases or just concat_axis==1? (this ambiguity is why i like to put comments inside below the "if"/"else")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the comment (yes, it applies only to the axis==1)
for arr in data1._mgr.arrays: | ||
arr.flags.writeable = False | ||
else: | ||
data1._mgr.blocks[0].values.flags.writeable = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could implement BlockManager.arrays as a property yielding the values for compat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but that would not help for this specific case (as those arrays would not be the actual arrays stored in the BlockManager, and setting the flag wouldn't have an impact on the actual values).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as those arrays would not be the actual arrays stored in the BlockManager
@property
def arrays(self):
for blk in self.blocks:
yield blk.values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, like that. I wouldn't find it great API design, as the same attribute/property would return something quite different (at least what you can do with it is different), but I am fine adding it for testing convenience
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added + test simplified
small comments, generally looks good |
@@ -754,10 +754,12 @@ def reindex_indexer( | |||
# ignored keywords | |||
consolidate: bool = True, | |||
only_slice: bool = False, | |||
# ArrayManager specific keywords | |||
do_integrity_check: bool = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we call this integrity_check elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BlockManager/ArrayManager constructors call this do_integrity_check
, so it's consistent with that. We don't have integrity_check
, but we do have verify_integrity
elsewhere (and this is actually used more, also in public APIs).
I think it might be good to change do_integrity_check
to verify_integrity
, but given that currently do_integrity_check
is consistently used within the (already existing) internals code, that's something for a different PR, I would say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right that's what i mean. can you normalize all to verify_integrity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you normalize all to verify_integrity
Since that's not strictly related to concat or ArrayManager, will do that in a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> #39989
pandas/core/internals/concat.py
Outdated
arrays = list(itertools.chain.from_iterable([mgr.arrays for mgr in mgrs])) | ||
return ArrayManager(arrays, [axes[1], axes[0]], do_integrity_check=False) | ||
|
||
|
||
def concatenate_block_managers( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you at a higher level call concatenate_array_managers instead? (e.g. instead of dispatching thru the BM)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require adding if/else checking the manager type in each of the places where currently concatenate_array_managers
is called (3 places), so that would not improve the code there.
If you want I can create a new concatenate_managers
in this file that simply does the dispatch to concatenate_block_managers
/ concatenate_array_managers
, and call that instead of concatenate_block_managers
outside of the /internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok maybe rename this then to concatenate_managers? to make it much more obvious.
OT should we create a Internal - ArrayManager label? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments
@@ -1381,7 +1391,9 @@ def test_merge_readonly(self): | |||
np.arange(20).reshape((5, 4)) + 1, columns=["a", "b", "x", "y"] | |||
) | |||
|
|||
data1._mgr.blocks[0].values.flags.writeable = False | |||
for arr in data1._mgr.arrays: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cabn you comment on this (I know what you are doing by seeing what you added, but is non-obvious here i think)
The windows failure is also happening on master, and the linux failure is a flaky resource warning, so both unrelated. Thanks for the reviews! Going to merge now, and will do the |
@@ -282,6 +282,18 @@ def get_dtypes(self): | |||
dtypes = np.array([blk.dtype for blk in self.blocks]) | |||
return algos.take_nd(dtypes, self.blknos, allow_fill=False) | |||
|
|||
@property | |||
def arrays(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annotate
The (hopefully) "easy" part of #39612 for which there seems less discussion: this separates the pieces from #39612 that are needed to get
concat
withaxis=1
working (concat_axis=0
), which at least enables the join / merge usecases.