Skip to content

CLN: remove IndexEngine.set_value #31510

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 10 commits into from
Feb 2, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

made possible bc Series._values now returns DTA/TDA for datetime64/timedelta64

Small perf improvement

In [3]: dti = pd.date_range('2016-01-01', freq='D', periods=10**4)              
In [4]: idx = list('abcdefghijklmnop')                                          
In [5]: arr = np.random.random(len(idx)*len(dti)).reshape(len(dti), -1)         
In [6]: df = pd.DataFrame(arr, index=dti, columns=idx)                          

In [7]: %timeit df2 = df._set_value("2043-05-14", "c", 4)                      
381 µs ± 14.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)   # <-- master
330 µs ± 13 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)  # <-- PR

@jbrockmendel jbrockmendel added Clean Indexing Related to indexing on series/frames, not to indexes themselves labels Feb 1, 2020
if util.is_bool_object(value):
raise ValueError("Cannot assign bool to float/integer series")

if issubclass(arr.dtype.type, (np.integer, np.bool_)):
if issubclass(dtype.type, (np.integer, np.bool_)):
Copy link
Contributor

Choose a reason for hiding this comment

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

i think much more clear if you reverse these no? (L588 first), then bool casting is out of the way.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not clear on what you're suggesting here. There is no bool casting in this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

reverse the order of the if elif, IOW handle the bool dtype.type first

else:
self.loc[label] = value
loc = self.index.get_loc(label)
libindex.validate_numeric_casting(self.dtype, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

would not be averse to you importing validate_numeric_casting at the top

@jreback jreback added this to the 1.1 milestone Feb 2, 2020
if util.is_float_object(value) and value != value:
raise ValueError("Cannot assign nan to integer series")

return value
if (issubclass(dtype.type, (np.integer, np.floating, np.complex)) and
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 not just do

elsif (.....) as by-definition they are not bools at this point.

Copy link
Member Author

Choose a reason for hiding this comment

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

the case where issubclass(dtype.type, np.integer) will pass through in both cases i think

@jreback jreback merged commit 000245a into pandas-dev:master Feb 2, 2020
@jreback
Copy link
Contributor

jreback commented Feb 2, 2020

ok this is fine

@jbrockmendel jbrockmendel deleted the set_value branch February 2, 2020 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants