question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remove_nans doesn't work

See original GitHub issue

Problem 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
barentsencommented, Sep 20, 2018

This behavior by design. Methods like remove_nans, remove_outliers, bin, flatten, normalize, etc all create and return a new LightCurve object rather than modifying the existing one. This enables method chaining, e.g. you can do lc.remove_outliers().bin().plot(). It also makes it easier to preserve the original LightCurve object.

This is similar to the design of pandas where e.g. df1 = df.sort_values(by='foo') does not modify df and instead creates a brand new dataframe df1. However pandas does provide an inplace parameter to change this behavior, e.g. df.sort_values(by='foo', inplace=True) does modify df 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!

0reactions
gullycommented, Sep 26, 2018

We could also consider adding an inplace operator. I am inclined to keep the current behavior for the purpose of method chaining.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found