-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: dtype-unaware (empty) objects ("any" dtype) #48110
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
Conversation
pandas/core/indexing.py
Outdated
@@ -2117,7 +2117,8 @@ def _setitem_with_indexer_missing(self, indexer, value): | |||
curr_dtype = getattr(curr_dtype, "numpy_dtype", curr_dtype) | |||
new_dtype = maybe_promote(curr_dtype, value)[0] | |||
else: | |||
new_dtype = None | |||
if isinstance(self.obj.dtype, object): |
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 don't think this is a good idea. This breaks the current behavior and the special case for object looks a bit weird. What happens if you assign a different dtype? This would still change which is inconsistent then-
Also you have to keep the fall through clause
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.
also wont this isinstance be True for everything?
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.
also wont this isinstance be True for everything? Yes. I should not do like this
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 don't think this is a good idea. This breaks the current behavior and the special case for object looks a bit weird. What happens if you assign a different dtype? This would still change which is inconsistent then-
Also you have to keep the fall through clause
From this issue #19647 , when adding element to empty object Series. The series should change based on type object which is set by user.
s = pd.Series(dtype='object')
s.loc['myint'] = 1
s.loc['myfloat'] = 2.
Expected output:
myint 1.0
myfloat 2.0
dtype: object
If I assign to different dtype, for example
s = pd.Series(dtype=float)
s.loc['myint'] = 1.0
s.loc['myfloat'] = 2
Output:
myint 1.0
myfloat 2.0
dtype: float64
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.
What happens if the empty series has some other dtype apart from object? Then this is not caught by your current change.
on the other side, if the dtype is the default this should still change, this is not covered here
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.
What happens if the empty series has some other dtype apart from object? Then this is not caught by your current change.
If the empty series has some other dtype apart from object, for example
s = pd.Series(dtype=float)
s.loc['myint'] = 1.0
s.loc['myfloat'] = 2
print(s)
Output will be like this
myint 1.0
myfloat 2.0
dtype: float64
… into dtype-unaware-19647
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.