Skip to content
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

panel.to_frame() discards nan by default #7879

Closed
hensing opened this issue Jul 30, 2014 · 17 comments
Closed

panel.to_frame() discards nan by default #7879

hensing opened this issue Jul 30, 2014 · 17 comments
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@hensing
Copy link

hensing commented Jul 30, 2014

As already described in issue #3690, panel.to_frame discards all minor entries with nan in the data, which can be very confusing. I believe there should be a warning, first time data is dropped or the opposite should be the default behavior.

The warning could be treated similar to a ZeroDivisionWarning in numpy only on the first occurrence.

See below for an example:

df1 = pd.DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'],
                   index=['foo', 'bar'])
df2 = pd.DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'],
                   index=['foo', 'bar'])
df2.loc['foo', 'B'] = np.nan
mydict = {'df1': df1, 'df2': df2}

pd.Panel(mydict).to_frame()

Output:

major minor df1 df2
foo A 1.9097545931480682 -0.6710202447941566
foo C 1.3335254610685865 1.53372538551507
bar A 0.3145550744497975 -1.7221352144306152
bar B -0.15681197178861878 -1.2308510354641322
bar C -0.09598971674309852 -0.1268630728124487

Using filter_observations=False, nan won't be dropped:

pd.Panel(mydict).to_frame(filter_observations=False)

Output:

major minor df1 df2
foo A 1.9097545931480682 -0.6710202447941566
foo B 2.092552358833253
foo C 1.333525461068586 1.53372538551507
bar A 0.3145550744497975 -1.7221352144306152
bar B -0.15681197178861878 -1.2308510354641322
bar C -0.09598971674309852 -0.1268630728124487
@TomAugspurger
Copy link
Contributor

+1 on a warning. This surprises me every time.

@m-novikov
Copy link

@jreback
I can fix broken tests, it's for most part causing problems becouse result of to_frame() changed length with new API.
But I'm not sure what to do with SparsePanel.to_frame() method which will raise exeption if filter_observations changed to False.
Else if I left along SpasePanel.to_frame method signatures of Panel.to_frame(filter_observations=False) and SparsePanel.to_frame(filter_observations=True) will be inconsistent.

@jreback
Copy link
Contributor

jreback commented Nov 2, 2014

can you show the error with SparsePanel. That's sort of a problem step-child. Prob noone uses it (and I never fixed it to inherit from NDFrame).

@springcoil
Copy link
Contributor

Sorry, @jreback how exactly do I do that? Do you want me to change some
errors?

On Mon, Nov 3, 2014 at 12:16 AM, jreback notifications@github.com wrote:

can you show the error with SparsePanel. That's sort of a problem
step-child. Prob noone uses it (and I never fixed it to inherit from
NDFrame).


Reply to this email directly or view it on GitHub
#7879 (comment).

Peadar Coyle
Skype: springcoilarch
www.twitter.com/springcoil
peadarcoyle.wordpress.com

@jreback
Copy link
Contributor

jreback commented Nov 2, 2014

just show a complete example and the error it outputs (when you change the default)

@eyurtsev
Copy link

eyurtsev commented Feb 4, 2015

This just got me. Took a long time to figure out why data was missing. 👍 for any solution. :)

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback modified the milestones: 0.17.0, Next Major Release Apr 8, 2015
@eyurtsev
Copy link

This got me yet one more time! 1 hour of troubleshooting. :)

@jreback
Copy link
Contributor

jreback commented Aug 15, 2015

pull-requests welcome to change this for 0.17.0

@hensing
Copy link
Author

hensing commented Aug 17, 2015

Is PR #8063 a solution or is it worth to write a new one or to change the default behavior?

@jreback
Copy link
Contributor

jreback commented Aug 18, 2015

@hensing so options are this

  • just change the default and document in the API section. This doesn't lose information, but could be unexpected for users. Though in this case ok with it.
  • deprecate filter_observations and replace with dropna (which is more consistent with the kw schema). Then you can change to the new default and show a deprecation warning for the originals.

@hensing
Copy link
Author

hensing commented Aug 18, 2015

@jreback solution № 2 (deprecate und change kw) seems for me to be the most elegant solution — I'll give it a try next weekend.

@jreback
Copy link
Contributor

jreback commented Aug 18, 2015

gr8!

@jreback
Copy link
Contributor

jreback commented Aug 26, 2015

@hensing status?

@hensing
Copy link
Author

hensing commented Aug 26, 2015

@jreback I couldn't work on that due to bike accident, sorry. Hope I can make it this weekend.

hensing added a commit to hensing/pandas that referenced this issue Aug 26, 2015
@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Aug 28, 2015
@jreback jreback modified the milestones: Next Major Release, 0.17.0 Sep 5, 2015
hensing added a commit to hensing/pandas that referenced this issue Sep 13, 2015
@saddy001
Copy link

saddy001 commented Feb 26, 2017

I am a bit confused: I'm using Pandas 19.2 and still have the default drop-behaviour with the filter_observations-Keyword.

pip3 show pandas
Version: 0.19.2
$ python3
import pandas
pandas.__version__
'0.19.2'

When I look into the source I see no changes regarding dropna etc:
panel.py line 879

What am I missing?

@jreback
Copy link
Contributor

jreback commented Feb 26, 2017

this is an open issue

iirc there a couple of pull requests that were almost there but did not get merged

welcome to have a complete one

@jreback jreback modified the milestones: won't fix, Next Major Release Jul 11, 2017
@jreback
Copy link
Contributor

jreback commented Jul 11, 2017

closing as Panel deprecated

@jreback jreback closed this as completed Jul 11, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
8 participants