Skip to content

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

Closed
wants to merge 9 commits into from

Conversation

ucals
Copy link

@ucals ucals commented Mar 29, 2017

@@ -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
Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Contributor

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).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't understand

Copy link
Author

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! :)

@@ -1226,7 +1225,6 @@ def test_from_to_scipy_object(spmatrix, fill_value):


class TestSparseDataFrameArithmetic(tm.TestCase):

Copy link
Contributor

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

Copy link
Author

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

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]
Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Mar 29, 2017
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]
Copy link
Contributor

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)

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]
Copy link
Contributor

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
Copy link

codecov bot commented Mar 29, 2017

Codecov Report

Merging #15834 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.72% <ø> (?)
#single 40.69% <ø> (?)
Impacted Files Coverage Δ
pandas/sparse/frame.py 94.26% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.56% <0%> (-0.1%) ⬇️
pandas/core/categorical.py 95.85% <0%> (ø) ⬆️
pandas/core/series.py 94.86% <0%> (ø) ⬆️
pandas/io/html.py 84.81% <0%> (+0.32%) ⬆️
pandas/core/common.py 91.3% <0%> (+0.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd169dc...04fba8d. Read the comment docs.

@jreback jreback added this to the 0.20.0 milestone Mar 30, 2017
@jreback jreback closed this in 1e0fbd2 Mar 30, 2017
mattip pushed a commit to mattip/pandas that referenced this pull request Apr 3, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: SparseDataFrame construction with lists not coercing to dtype
2 participants