Skip to content

CLN: Deduplicate code in duplicated #49550

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 3 commits into from
Nov 7, 2022
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
25 changes: 6 additions & 19 deletions pandas/_libs/hashtable_func_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,18 @@ cdef duplicated_{{dtype}}(const {{dtype}}_t[:] values, object keep='first', cons
if keep not in ('last', 'first', False):
raise ValueError('keep must be either "first", "last" or False')

if keep == 'last':
{{for cond, keep in [('if', '"last"'), ('elif', '"first"')]}}
{{cond}} keep == {{keep}}:
{{if dtype == 'object'}}
if True:
{{else}}
with nogil:
{{endif}}
{{if keep == '"last"'}}
for i in range(n - 1, -1, -1):
# equivalent: range(n)[::-1], which cython doesn't like in nogil
Copy link
Member

Choose a reason for hiding this comment

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

is this comment no longer relevant?

Copy link
Member Author

@phofl phofl Nov 5, 2022

Choose a reason for hiding this comment

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

It is still relevant, but imo

range(n - 1, -1, -1)

is clearer than range(n)[::-1] anyway, so thought removing this would be fine.

if uses_mask and mask[i]:
if seen_na:
out[i] = True
else:
out[i] = False
seen_na = True
else:
value = {{to_c_type}}(values[i])
kh_put_{{ttype}}(table, value, &ret)
out[i] = ret == 0

elif keep == 'first':
{{if dtype == 'object'}}
if True:
{{else}}
with nogil:
{{endif}}
{{else}}
for i in range(n):
{{endif}}
if uses_mask and mask[i]:
if seen_na:
out[i] = True
Expand All @@ -177,6 +163,7 @@ cdef duplicated_{{dtype}}(const {{dtype}}_t[:] values, object keep='first', cons
value = {{to_c_type}}(values[i])
kh_put_{{ttype}}(table, value, &ret)
out[i] = ret == 0
{{endfor}}

else:
{{if dtype == 'object'}}
Expand Down