-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Adding a warning when dropping NA values for panel.to_frame #7879 #8063
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
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
19391f8
Adding a warning when dropping NA values for panel.to_frame #7879
Magellanea 63d5a3e
Adding missing import statement for warnings module
Magellanea f0f75fc
modify test cases to use tm.assert_produces_warning
Magellanea 3bd040e
Minor fix - allow warning repetition from same source
Magellanea 982c828
change ```filter_observation``` to be true by default, change other t…
Magellanea 2e0180d
Fix tests for sparse module
Magellanea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import nose | ||
|
||
import numpy as np | ||
|
||
import warnings | ||
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex | ||
from pandas.core.datetools import bday | ||
from pandas.core.panel import Panel | ||
|
@@ -1556,6 +1556,36 @@ def test_to_frame_multi_drop_level(self): | |
expected = DataFrame({'i1': [1., 2], 'i2': [1., 2]}, index=exp_idx) | ||
assert_frame_equal(result, expected) | ||
|
||
def test_to_frame_na_drop_warnings(self): | ||
def create_a_panel_with_na_vals(filter_observations=True): | ||
df1 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], | ||
index=['foo', 'bar']) | ||
df2 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], | ||
index=['foo', 'bar']) | ||
df2.loc['foo', 'B'] = np.nan | ||
dict_with_dropped_vals = {'df1': df1, 'df2': df2} | ||
Panel(dict_with_dropped_vals).\ | ||
to_frame(filter_observations=filter_observations) | ||
|
||
def create_a_panel_without_na_vals(filter_observations=True): | ||
df1 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], | ||
index=['foo', 'bar']) | ||
df2 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], | ||
index=['foo', 'bar']) | ||
dict_with_dropped_vals = {'df1': df1, 'df2': df2} | ||
Panel(dict_with_dropped_vals).\ | ||
to_frame(filter_observations=filter_observations) | ||
with warnings.catch_warnings(record=True) as w: | ||
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. We have a context manger called You can call it like with tm.assert_produces_warning(RuntimeWarning):
panel.to_frame() then break each of your test cases into to separate lines. You can also check that a warning isn't raised with
|
||
warnings.simplefilter("always") | ||
create_a_panel_with_na_vals() | ||
create_a_panel_with_na_vals(False) | ||
create_a_panel_without_na_vals() | ||
create_a_panel_without_na_vals(False) | ||
self.assertEqual(len(w), 1) | ||
self.assertTrue(issubclass(w[0].category, RuntimeWarning)) | ||
self.assertEqual(str(w[0].message), | ||
"NaN values found, empty values will be dropped") | ||
|
||
def test_to_panel_na_handling(self): | ||
df = DataFrame(np.random.randint(0, 10, size=20).reshape((10, 2)), | ||
index=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1], | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'll need to import warnings in this file too