-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: SparseDataFrame construction with lists not coercing to dtype (GH 15682) #15834
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 7 commits
676a4e5
e12bca7
9fc617b
8b463cb
43456a5
faa5c5c
cc4c15b
483bb2c
04fba8d
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 |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
|
||
|
||
class TestSparseDataFrame(tm.TestCase, SharedWithSparse): | ||
|
||
klass = SparseDataFrame | ||
|
||
def setUp(self): | ||
|
@@ -758,7 +757,8 @@ def test_sparse_frame_fillna_limit(self): | |
def test_rename(self): | ||
# just check this works | ||
renamed = self.frame.rename(index=str) # noqa | ||
renamed = self.frame.rename(columns=lambda x: '%s%d' % (x, len(x))) # noqa | ||
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. can you compare these results (as no tests before). 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. didn't understand 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. ok, just figured it out, added the right test on my last commit! :) |
||
renamed = self.frame.rename( | ||
columns=lambda x: '%s%d' % (x, len(x))) # noqa | ||
|
||
def test_corr(self): | ||
res = self.frame.corr() | ||
|
@@ -967,7 +967,6 @@ def _check(frame, orig): | |
def test_shift(self): | ||
|
||
def _check(frame, orig): | ||
|
||
shifted = frame.shift(0) | ||
exp = orig.shift(0) | ||
tm.assert_frame_equal(shifted.to_dense(), exp) | ||
|
@@ -1060,7 +1059,7 @@ def test_sparse_pow_issue(self): | |
df = SparseDataFrame({'A': [nan, 0, 1]}) | ||
|
||
# note that 2 ** df works fine, also df ** 1 | ||
result = 1**df | ||
result = 1 ** df | ||
|
||
r1 = result.take([0], 1)['A'] | ||
r2 = result['A'] | ||
|
@@ -1126,7 +1125,7 @@ def test_isnotnull(self): | |
tm.assert_frame_equal(res.to_dense(), exp) | ||
|
||
|
||
@pytest.mark.parametrize('index', [None, list('ab')]) # noqa: F811 | ||
@pytest.mark.parametrize('index', [None, list('ab')]) # noqa: F811 | ||
@pytest.mark.parametrize('columns', [None, list('cd')]) | ||
@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) | ||
@pytest.mark.parametrize('dtype', [bool, int, float, np.uint16]) | ||
|
@@ -1180,7 +1179,7 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): | |
tm.assert_equal(sdf.to_coo().dtype, np.object_) | ||
|
||
|
||
@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) # noqa: F811 | ||
@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) # noqa: F811 | ||
def test_from_to_scipy_object(spmatrix, fill_value): | ||
# GH 4343 | ||
dtype = object | ||
|
@@ -1226,7 +1225,6 @@ def test_from_to_scipy_object(spmatrix, fill_value): | |
|
||
|
||
class TestSparseDataFrameArithmetic(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. try to turn off this removing blank lines like this 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 put it back, sorry |
||
def test_numeric_op_scalar(self): | ||
df = pd.DataFrame({'A': [nan, nan, 0, 1, ], | ||
'B': [0, 1, 2, nan], | ||
|
@@ -1255,7 +1253,6 @@ def test_comparison_op_scalar(self): | |
|
||
|
||
class TestSparseDataFrameAnalytics(tm.TestCase): | ||
|
||
def setUp(self): | ||
self.data = {'A': [nan, nan, nan, 0, 1, 2, 3, 4, 5, 6], | ||
'B': [0, 1, 2, nan, nan, nan, 3, 4, 5, 6], | ||
|
@@ -1299,3 +1296,12 @@ def test_numpy_func_call(self): | |
'std', 'min', 'max'] | ||
for func in funcs: | ||
getattr(np, func)(self.frame) | ||
|
||
def test_type_coercion_at_construction(self): | ||
# GH 15682 | ||
df = pd.SparseDataFrame( | ||
{'a': [1, 0, 0], 'b': [0, 1, 0], 'c': [0, 0, 1]}, dtype='uint8', | ||
default_fill_value=0) | ||
result = df.dtypes[0] | ||
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. create the result and use 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 can use the comparison from the issue (IOW construct both ways and compare) 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. move this test where other 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. done |
||
expected = np.dtype('uint8') | ||
assert result == expected |
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.
you would do this in
sp_maker
, also don't use if/else on a single line (hard to read)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.
done