Skip to content

DOC: improve fillna() doc for limit keyword (fixes #10002) #10009

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

Merged
merged 1 commit into from
Apr 29, 2015

Conversation

mortada
Copy link
Contributor

@mortada mortada commented Apr 28, 2015

fixes #10002

Maximum size gap to forward or backward fill (not implemented yet!)
If method is specified, this is the maximum size gap to forward or backward
fill. Otherwise this is the maximum number of entries along the axis where
holes will be filled. (not implemented yet!)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe put the not implemented yet first? (and maybe also explicitely "for Categorical")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, will update

@jorisvandenbossche
Copy link
Member

Actually, in the way I interpret "maximum size gap to forward or backward fill", this is not fully correct.

I interpret it as "only fill that gap if the gap is not larger as 'limit'", but it is "per gap, fill a maximum numbers of 'limit'":

In [10]: s=pd.Series(range(4), index=[1,2,5,9])

In [11]: s = s.reindex(range(10))

In [12]: s
Out[12]:
0   NaN
1     0
2     1
3   NaN
4   NaN
5     2
6   NaN
7   NaN
8   NaN
9     3
dtype: float64

In [13]: s.fillna(method='ffill', limit=2)
Out[13]:
0   NaN
1     0
2     1
3     1
4     1
5     2
6     2
7     2
8   NaN
9     3
dtype: float64

@mortada
Copy link
Contributor Author

mortada commented Apr 29, 2015

What if we rephrase it to say something like:

"maximum number of consecutive holes to forward or backward fill"

@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Apr 29, 2015
@jreback jreback added this to the 0.16.1 milestone Apr 29, 2015
@jreback
Copy link
Contributor

jreback commented Apr 29, 2015

lgtm

@jorisvandenbossche
Copy link
Member

It is a bit subjective, but I would personally still interpret that not fully correct (I see a hole as possibly multiple NaN values if they are consecutive, but maybe this is not correct language?).
Otherwise: "maximum number of consecutive NaN values to forward/backward file per hole"

I think an example in the docstring to show this behaviour would possibly be the most clarifying.

@mortada
Copy link
Contributor Author

mortada commented Apr 29, 2015

Ah yeah I suppose you could interpret a "hole" as multiple NaNs. @jorisvandenbossche please see the updated changes in the diff, I wonder if it's now clear to you.

NaN values to forward/backward fill. In other words, if there is
a gap with more than this number of consecutive NaNs, it will only
be partially filled. If method is not specified, this is the
maximum number of entries along the axis where NaNs will be filled.
Copy link
Member

Choose a reason for hiding this comment

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

one small nitpick: maybe "along the entire axis"

For the rest everything clear now! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure definitely more clear now, thanks!

jorisvandenbossche added a commit that referenced this pull request Apr 29, 2015
DOC: improve fillna() doc for limit keyword (fixes #10002)
@jorisvandenbossche jorisvandenbossche merged commit e3c7862 into pandas-dev:master Apr 29, 2015
@jorisvandenbossche
Copy link
Member

Thanks!

@mortada mortada deleted the fillna_doc_fix branch April 29, 2015 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of 'limit' keyword when filling with a value
3 participants