PERF: use blk.dtype in where() & _setitem_frame() #61014
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.


where()#61010 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.this pr is a one-line change to the code here:
pandas/pandas/core/generic.py
Lines 9735 to 9737 in d1ec1a4
Performance comparison:
test script:
for _dt in cond.dtypes:
10 0.002963045029900968

1000 0.006705133942887187
100000 0.40306550299283117
10000000 46.55275956704281
for _dt in cond.dtypes.unique():
10 0.0028260269900783896

1000 0.002695770002901554
100000 0.042065858957357705
10000000 6.068146598991007
for _dt in [blk.dtype for blk in cond._mgr.blocks]:
10 0.0009857049444690347

1000 0.0011893719201907516
100000 0.003112988080829382
10000000 0.13763279700651765