remove_nans doesn't work
See original GitHub issueProblem description
lightkurve.lightcurve.FoldedLightCurve.remove_nans doesn’t seem to remove nans at all.
Example
import numpy as np
from lightkurve import KeplerLightCurveFile
KIC = 4570949
lc = KeplerLightCurveFile.from_archive(str(KIC), quarter=3, verbose=False).PDCSAP_FLUX
print(len(lc.flux[np.isnan(lc.flux)]))
lc.remove_nans()
print(len(lc.flux[np.isnan(lc.flux)]))
The result prints as 6 6 which suggests to me that there are as many nans before as after applying remove_nans.
Expected behavior
I expected the flux array to no longer contain nans.
Environment:
- platform (e.g. Linux, OSX, Windows): OSx
- lightkurve version (e.g. 1.0b6): 1.0b15
- installation method (e.g. pip, conda, source): pip
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Can't drop NAN with dropna in pandas - Stack Overflow
From the result, the dropna line doesn't work because the row number doesn't change and there is still NAN in the dataframe. How...
Read more >remove_nans doesn't work · Issue #256 · lightkurve ... - GitHub
I expected the flux array to no longer contain nans. Environment: platform (e.g. Linux, OSX, Windows): OSx; lightkurve version (e.g. 1.0b6): 1.0 ...
Read more >How can I remove NaN values from a matrix? - MATLAB Central
The line I have to remove the NaN's runs, it's just not removing them. I'm not sure what isn't working. How do I...
Read more >Remove NaNs from ExpressionSet class object - Biostars
Sometimes in microarray analysis, some datasets contain NaN values, I need to remove NaNs from gset to ex matrix will be without NaNs...
Read more >Pandas Drop Rows with NaN Values in DataFrame
Use dropna() function to drop rows with NaN/None values in pandas DataFrame. Python doesn't support Null hence any missing data is represented as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This behavior by design. Methods like
remove_nans
,remove_outliers
,bin
,flatten
,normalize
, etc all create and return a newLightCurve
object rather than modifying the existing one. This enables method chaining, e.g. you can dolc.remove_outliers().bin().plot()
. It also makes it easier to preserve the originalLightCurve
object.This is similar to the design of
pandas
where e.g.df1 = df.sort_values(by='foo')
does not modifydf
and instead creates a brand new dataframedf1
. However pandas does provide aninplace
parameter to change this behavior, e.g.df.sort_values(by='foo', inplace=True)
does modifydf
directly.I am open to a discussion about whether or not the “method chaining” design we are using here is the right approach for Lightkurve. My default would be to keep it because we’re already invested in it, but we can still change it before the true 1.0 release if there are very compelling reasons!
We could also consider adding an
inplace
operator. I am inclined to keep the current behavior for the purpose of method chaining.