-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: multi-type SparseDataFrame fixes and improvements #13917
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 6 commits
2e833fa
fb6237c
c7fb0f2
114217e
33973a5
93d2de6
6782bc7
2104948
ac790d7
eebcb23
8d675ad
442b8c1
926ca1e
057d56b
8c7d1ea
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 |
---|---|---|
|
@@ -104,15 +104,20 @@ def test_as_matrix_lcd(self): | |
values = self.mixed_float.as_matrix(['C']) | ||
self.assertEqual(values.dtype, np.float16) | ||
|
||
# B uint64 forces float because there are other signed int types | ||
values = self.mixed_int.as_matrix(['A', 'B', 'C', 'D']) | ||
self.assertEqual(values.dtype, np.int64) | ||
self.assertEqual(values.dtype, np.float64) | ||
|
||
values = self.mixed_int.as_matrix(['A', 'D']) | ||
self.assertEqual(values.dtype, np.int64) | ||
|
||
# guess all ints are cast to uints.... | ||
# B uint64 forces float because there are other signed int types | ||
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. this might fix another bug, can you search for uint64 issues and see? 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. add the issue as a reference here |
||
values = self.mixed_int.as_matrix(['A', 'B', 'C']) | ||
self.assertEqual(values.dtype, np.int64) | ||
self.assertEqual(values.dtype, np.float64) | ||
|
||
# as B and C are both unsigned, no forcing to float is needed | ||
values = self.mixed_int.as_matrix(['B', 'C']) | ||
self.assertEqual(values.dtype, np.uint64) | ||
|
||
values = self.mixed_int.as_matrix(['A', 'C']) | ||
self.assertEqual(values.dtype, np.int32) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2713,6 +2713,65 @@ def test_type_error_multiindex(self): | |
assert_series_equal(result, expected) | ||
|
||
|
||
class TestSparseDataFrameMultitype(tm.TestCase): | ||
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. these need to go in |
||
def setUp(self): | ||
super(TestSparseDataFrameMultitype, self).setUp() | ||
self.string_series = pd.SparseSeries(['a', 'b', 'c']) | ||
self.int_series = pd.SparseSeries([1, 2, 3]) | ||
self.float_series = pd.SparseSeries([1.1, 1.2, 1.3]) | ||
self.object_series = pd.SparseSeries([[], {}, set()]) | ||
self.sdf = pd.SparseDataFrame({ | ||
'string': self.string_series, | ||
'int': self.int_series, | ||
'float': self.float_series, | ||
'object': self.object_series, | ||
}) | ||
self.cols = ['string', 'int', 'float', 'object'] | ||
self.sdf = self.sdf[self.cols] | ||
|
||
def test_basic_dtypes(self): | ||
for _, row in self.sdf.iterrows(): | ||
self.assertEqual(row.dtype, object) | ||
tm.assert_sp_series_equal(self.sdf['string'], self.string_series, | ||
check_names=False) | ||
tm.assert_sp_series_equal(self.sdf['int'], self.int_series, | ||
check_names=False) | ||
tm.assert_sp_series_equal(self.sdf['float'], self.float_series, | ||
check_names=False) | ||
tm.assert_sp_series_equal(self.sdf['object'], self.object_series, | ||
check_names=False) | ||
|
||
def test_indexing_single(self): | ||
tm.assert_sp_series_equal(self.sdf.iloc[0], | ||
pd.SparseSeries(['a', 1, 1.1, []], | ||
index=self.cols), | ||
check_names=False) | ||
tm.assert_sp_series_equal(self.sdf.iloc[1], | ||
pd.SparseSeries(['b', 2, 1.2, {}], | ||
index=self.cols), | ||
check_names=False) | ||
tm.assert_sp_series_equal(self.sdf.iloc[2], | ||
pd.SparseSeries(['c', 3, 1.3, set()], | ||
index=self.cols), | ||
check_names=False) | ||
|
||
def test_indexing_multiple(self): | ||
tm.assert_sp_frame_equal(self.sdf, self.sdf[:]) | ||
tm.assert_sp_frame_equal(self.sdf, self.sdf.loc[:]) | ||
tm.assert_sp_frame_equal(self.sdf.iloc[[1, 2]], | ||
pd.SparseDataFrame({ | ||
'string': ['b', 'c'], | ||
'int': [2, 3], | ||
'float': [1.2, 1.3], | ||
'object': [{}, set()] | ||
}, index=[1, 2])[self.cols]) | ||
tm.assert_sp_frame_equal(self.sdf[['int', 'string']], | ||
pd.SparseDataFrame({ | ||
'int': self.int_series, | ||
'string': self.string_series, | ||
})) | ||
|
||
|
||
class TestDataFrameIndexingDatetimeWithTZ(tm.TestCase, TestData): | ||
|
||
_multiprocess_can_split_ = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1856,3 +1856,29 @@ def test_multilevel_preserve_name(self): | |
result2 = s.ix['foo'] | ||
self.assertEqual(result.name, s.name) | ||
self.assertEqual(result2.name, s.name) | ||
|
||
|
||
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. same here |
||
class TestSparseSeriesMultitype(tm.TestCase): | ||
def setUp(self): | ||
super(TestSparseSeriesMultitype, self).setUp() | ||
self.index = ['string', 'int', 'float', 'object'] | ||
self.ss = pd.SparseSeries(['a', 1, 1.1, []], | ||
index=self.index) | ||
|
||
def test_indexing_single(self): | ||
for i, idx in enumerate(self.index): | ||
self.assertEqual(self.ss.iloc[i], self.ss[idx]) | ||
self.assertEqual(type(self.ss.iloc[i]), | ||
type(self.ss[idx])) | ||
self.assertEqual(self.ss['string'], 'a') | ||
self.assertEqual(self.ss['int'], 1) | ||
self.assertEqual(self.ss['float'], 1.1) | ||
self.assertEqual(self.ss['object'], []) | ||
|
||
def test_indexing_multiple(self): | ||
tm.assert_sp_series_equal(self.ss.loc[['string', 'int']], | ||
pd.SparseSeries(['a', 1], | ||
index=['string', 'int'])) | ||
tm.assert_sp_series_equal(self.ss.loc[['string', 'object']], | ||
pd.SparseSeries(['a', []], | ||
index=['string', '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.
Bug in single row slicing on multi-dtype
SparseDataFrame
s.....