-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: upcasting on reshaping ops #13247 #15594
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
Changes from 2 commits
468baee
45f7ae9
4b1e5c6
b977615
d3476c0
4f6c03e
8fec07c
0e52b74
8122359
a1d5d40
5bb72c7
6744636
1fa578b
3cd1734
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1899,3 +1899,64 @@ def test_concat_multiindex_dfs_with_deepcopy(self): | |
tm.assert_frame_equal(result_copy, expected) | ||
result_no_copy = pd.concat(example_dict, names=['testname']) | ||
tm.assert_frame_equal(result_no_copy, expected) | ||
|
||
def test_concat_no_unnecessary_upcats(self): | ||
# GH 13247 | ||
for pdt in [pd.Series, pd.DataFrame, pd.Panel, pd.Panel4D]: | ||
dims = pdt().ndim | ||
for dt in np.sctypes['float']: | ||
dfs = [pdt(np.array([1], dtype=dt, ndmin=dims)), | ||
pdt(np.array([np.nan], dtype=dt, ndmin=dims)), | ||
pdt(np.array([5], dtype=dt, ndmin=dims))] | ||
x = pd.concat(dfs) | ||
self.assertTrue(x.values.dtype == dt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just do |
||
|
||
for dt in (np.sctypes['int'] + np.sctypes['uint']): | ||
dfs = [pdt(np.array([1], dtype=dt, ndmin=dims)), | ||
pdt(np.array([5], dtype=dt, ndmin=dims))] | ||
x = pd.concat(dfs) | ||
self.assertTrue(x.values.dtype == dt) | ||
|
||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.float32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims))) | ||
self.assertTrue(pd.concat(objs).values.dtype == np.float32) | ||
|
||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.int64, ndmin=dims))) | ||
self.assertTrue(pd.concat(objs).values.dtype == np.int64) | ||
|
||
# not sure what is the best answer here | ||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need these tests as you have the ones below |
||
self.assertTrue(pd.concat(objs).values.dtype == np.float64) | ||
|
||
@parametrize('dtype', np.sctypes('float')) | ||
@parametrize('klass', [Series, DataFrame, Panel]) | ||
def test_concat_no_unnecessary_upcats_pytest(self, dtype, klass): | ||
# GH 13247 | ||
for pdt in klass: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be misreading this, but I don't think you need the for loop over import numpy as np
from pandas import Series, DataFrame, Panel
import pandas as pd
import pytest
class TestConcatUpcast(object):
@pytest.mark.parametrize('pdt', [Series, DataFrame, Panel])
def test_concat_no_unnecessary_upcats_pytest(self, pdt):
# GH 13247
dims = pdt().ndim
for dt in np.sctypes['float']:
dfs = [pdt(np.array([1], dtype=dt, ndmin=dims)),
pdt(np.array([np.nan], dtype=dt, ndmin=dims)),
pdt(np.array([5], dtype=dt, ndmin=dims))]
x = pd.concat(dfs)
assert x.values.dtype == dt
objs = []
objs.append(pdt(np.array([1], dtype=np.float32, ndmin=dims)))
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims)))
assert pd.concat(objs).values.dtype == np.float32
objs = []
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims)))
objs.append(pdt(np.array([1], dtype=np.int64, ndmin=dims)))
assert pd.concat(objs).values.dtype == np.int64
objs = []
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims)))
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims)))
assert pd.concat(objs).values.dtype == np.float64 This doesn't parametrize all that well over the If you want to leave comments on #15608, would appreciate your insight. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm okay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You were right. |
||
dims = pdt().ndim | ||
for dt in dtype: | ||
dfs = [pdt(np.array([1], dtype=dt, ndmin=dims)), | ||
pdt(np.array([np.nan], dtype=dt, ndmin=dims)), | ||
pdt(np.array([5], dtype=dt, ndmin=dims))] | ||
x = pd.concat(dfs) | ||
self.assertTrue(x.values.dtype == dt) | ||
|
||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.float32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims))) | ||
self.assertTrue(pd.concat(objs).values.dtype == np.float32) | ||
|
||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.int64, ndmin=dims))) | ||
self.assertTrue(pd.concat(objs).values.dtype == np.int64) | ||
|
||
objs = [] | ||
objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims))) | ||
objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims))) | ||
self.assertTrue(pd.concat(objs).values.dtype == np.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.
can u write this in pytest form using parametrize (needs to be a separate function)
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.
Okay, but I need to read up on documentation and it might take some time.
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.
sure will be something like
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.
FYI only need to do Series/DataFrame/Panel
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 need
pytest
module for using@parametrize
.Should I create another class for pytest?