Skip to content

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

Closed
wants to merge 11 commits into from

Conversation

weikhor
Copy link
Contributor

@weikhor weikhor commented Aug 16, 2022

@@ -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):
Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

@weikhor weikhor Aug 17, 2022

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

@weikhor weikhor Aug 18, 2022

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

@mroeschke mroeschke added the Dtype Conversions Unexpected or buggy dtype conversions label Aug 16, 2022
@weikhor weikhor closed this Aug 17, 2022
@weikhor weikhor reopened this Aug 17, 2022
@jbrockmendel
Copy link
Member

@weikhor addressing #19647 is going to be really complicated, and require a consensus about API design that hasn't been achieved.

@weikhor
Copy link
Contributor Author

weikhor commented Aug 18, 2022

@weikhor addressing #19647 is going to be really complicated, and require a consensus about API design that hasn't been achieved.

Ok understand . thank. I will close this PR .

@weikhor weikhor closed this Aug 18, 2022
@weikhor weikhor reopened this Aug 20, 2022
@weikhor weikhor closed this Aug 20, 2022
@weikhor weikhor deleted the dtype-unaware-19647 branch August 20, 2022 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dtype-unaware (empty) objects ("any" dtype)
4 participants