Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Dataframe column dtype changed from int8 to int64 when setting complete column #11638
Comments
|
hmm, I recall seeing almost the same issue, but can't locate ATM. yep, looks buggy. pull-requests to fix are welcome. |
jreback
added Bug Indexing Dtypes
labels
Nov 18, 2015
jreback
added this to the
Next Major Release
milestone
Nov 18, 2015
|
@jreback In comman.py # provide implicity upcast on scalars
elif is_integer(val):
dtype = np.int64
elif is_float(val):
dtype = np.float64if there is no specific requirement for upcasting, then I can do a PR . |
|
this is actually tricky. do alternatively you can do
etc (this might be better) |
|
We are calling _infer_dtype_from_scalar(val) which is already doing this job. How does it solve the problem ? Am I missing something ? |
|
right......so must be someplace else then (because |
|
As pointed earlier , how about modifying _infer_dtype_from_scalar(val) and use np.issubdtype inside is_integer(val) and is_float(val) function to provide support for all kind of int and float types ? I am assuming that this will generate the same error for float types as well. |
|
how would that help? |
|
If we modify integer and float conditions in _infer_dtype_from_scalar(val) like this elif is_integer(val):
if isinstance(val, int):
dtype = np.int64
else:
dtype = type(val)
elif is_float(val):
if isinstance(val, float):
dtype = np.float64
else:
dtype = type(val)It will resolve the discrepancy without breaking anything. Please suggest . |
|
ahh, the problem is this:
you can try that change that you are suggesting above and see what breaks (and of course add a test for this behavior). It looks like it should work. |
varun-kr
referenced
this issue
Nov 19, 2015
Closed
BUG #11638 return correct dtype for int and float #11644
jreback
modified the milestone: 0.17.1, Next Major Release
Nov 19, 2015
varun-kr
added a commit
to varun-kr/pandas
that referenced
this issue
Nov 19, 2015
|
|
varun-kr |
c61020e
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Nov 20, 2015
|
|
varun-kr + jreback |
24cdf45
|
|
closed by #11644 |
jreback
closed this
Nov 20, 2015
jreback
added a commit
to jreback/pandas
that referenced
this issue
Nov 20, 2015
|
|
jreback |
b52b7fc
|
|
Wow, thank you for the quick fix. I was going to try but got lost in the pandas internals. Maybe next time |
jreback
added a commit
that referenced
this issue
Nov 20, 2015
|
|
jreback |
a3fd834
|
|
thank @varun-kr ! |
yarikoptic
added a commit
to neurodebian/pandas
that referenced
this issue
Dec 3, 2015
|
|
yarikoptic |
9b2e35f
|
cpaulik commentedNov 18, 2015
The following example should explain:
So it is cast to the correct dtype if a slice of the column is changed but setting the whole column changes the dtype even when explicitly set to
np.int8