Skip to content

PERF: BlockManager.equals blockwise #35357

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 13 commits into from
Aug 7, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

No description provided.

@jreback jreback added Internals Related to non-user accessible pandas implementation Performance Memory or execution speed performance labels Jul 20, 2020
return False
left = self.blocks[0].values
right = other.blocks[0].values
def blk_func(left, right):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this module left

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you do this; make this a module level function

@@ -34,21 +31,31 @@ def operate_blockwise(
right_ea = not isinstance(rblk.values, np.ndarray)

lvals, rvals = _get_same_shape_values(blk, rblk, left_ea, right_ea)
yield lvals, rvals, locs, left_ea, right_ea, rblk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe yield a NamedTuple?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC there are issues with NamedTuple construction performance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe wait a couple of days and use a dataclass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC there are issues with NamedTuple construction performance

really? can you point to something that shows this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be out of date but I think this is where i got the impression that NamedTuple has perf issues: https://lwn.net/Articles/731423/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer readability here
unless it's way slower



def blockwise_all(left: "BlockManager", right: "BlockManager", op) -> bool:
for lvals, rvals, _, _, _, _ in _iter_block_pairs(left, right):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a doc-string (also using a NamedTuple makes this easier to read here)

return False
left = self.blocks[0].values
right = other.blocks[0].values
def blk_func(left, right):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you do this; make this a module level function

)


def _iter_block_pairs(left: "BlockManager", right: "BlockManager"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you type the output

def _iter_block_pairs(left: "BlockManager", right: "BlockManager"):
def _iter_block_pairs(
left: "BlockManager", right: "BlockManager"
) -> Generator[BlockPairInfo, None, None]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterable (or Iterator) is adequate.

from https://mypy.readthedocs.io/en/stable/kinds_of_types.html#generators

A basic generator that only yields values can be annotated as having a return type of either Iterator[YieldType] or Iterable[YieldType].

@@ -127,3 +134,17 @@ def blockwise_all(left: "BlockManager", right: "BlockManager", op) -> bool:
if not res:
return False
return True


def array_equals(left: ArrayLike, right: ArrayLike) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the inputs are ArrayLike and not block related, would it make sense to co-locate this with array_equivalent in core\dtypes\missing.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@jbrockmendel
Copy link
Member Author

updated+green

elif isinstance(left, ABCExtensionArray):
return left.equals(right)
elif isinstance(right, ABCExtensionArray):
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this elif block is not needed since you already checked that the dtypes are equal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, will update

@jbrockmendel
Copy link
Member Author

updated+green

@jreback jreback added this to the 1.2 milestone Aug 7, 2020
@jreback jreback merged commit 067f86f into pandas-dev:master Aug 7, 2020
@jreback
Copy link
Contributor

jreback commented Aug 7, 2020

very nice

@jbrockmendel jbrockmendel deleted the perf-equals branch August 7, 2020 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants