-
-
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
Conversation
pandas/sparse/frame.py
Outdated
@@ -159,7 +159,7 @@ def _init_dict(self, data, index, columns, dtype=None): | |||
v = [v.get(i, nan) for i in index] | |||
|
|||
v = sp_maker(v) | |||
sdict[k] = v | |||
sdict[k] = v.astype(np.dtype(dtype)) if dtype is not None else v |
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
pandas/tests/sparse/test_frame.py
Outdated
@@ -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 comment
The 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 comment
The 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 comment
The 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! :)
pandas/tests/sparse/test_frame.py
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
just put it back, sorry
pandas/tests/sparse/test_frame.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
create the result and use assert_sp_frame_equal
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
move this test where other test_constructor
tests are
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
pandas/tests/sparse/test_frame.py
Outdated
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 comment
The 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)
pandas/tests/sparse/test_frame.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
move this test where other test_constructor
tests are
Codecov Report
@@ Coverage Diff @@
## master #15834 +/- ##
==========================================
- Coverage 90.97% 90.96% -0.02%
==========================================
Files 143 143
Lines 49429 49442 +13
==========================================
+ Hits 44969 44973 +4
- Misses 4460 4469 +9
Continue to review full report at Codecov.
|
…H 15682) closes pandas-dev#15682 Author: Carlos Souza <[email protected]> Closes pandas-dev#15834 from ucals/bug-fix-15682 and squashes the following commits: 04fba8d [Carlos Souza] Adding test_rename test cases (were missing) 483bb2c [Carlos Souza] Doing adjustments as per @jreback requests cc4c15b [Carlos Souza] Fixing coersion bug at SparseDataFrame construction faa5c5c [Carlos Souza] Merge remote-tracking branch 'upstream/master' 43456a5 [Carlos Souza] Merge remote-tracking branch 'upstream/master' 8b463cb [Carlos Souza] Merge remote-tracking branch 'upstream/master' 9fc617b [Carlos Souza] Merge remote-tracking branch 'upstream/master' e12bca7 [Carlos Souza] Sync fork 676a4e5 [Carlos Souza] Test
git diff upstream/master --name-only -- '*.py' | flake8 --diff