From e1994ea978536170a112cff1d0e45f7ae139a521 Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues Date: Sat, 10 Mar 2018 16:06:19 -0300 Subject: [PATCH 1/2] Docstring enhacement for asof method --- pandas/core/generic.py | 89 ++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9f2112729a503..14a1ec2ee0d25 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5400,40 +5400,61 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, # Timeseries methods Methods def asof(self, where, subset=None): - """ - The last row without any NaN is taken (or the last row without - NaN considering only the subset of columns in the case of a DataFrame) - - .. versionadded:: 0.19.0 For DataFrame - - If there is no good value, NaN is returned for a Series - a Series of NaN values for a DataFrame - - Parameters - ---------- - where : date or array of dates - subset : string or list of strings, default None - if not None use these columns for NaN propagation - - Notes - ----- - Dates are assumed to be sorted - Raises if this is not the case - - Returns - ------- - where is scalar - - - value or NaN if input is Series - - Series if input is DataFrame - - where is Index: same shape object as input - - See Also - -------- - merge_asof - - """ + """ + Take the last row without any NaN + + Or the last row without + NaN considering only the subset of columns in the case of a DataFrame + + .. versionadded:: 0.19.0 For DataFrame + + If there is no good value, NaN is returned for a Series + a Series of NaN values for a DataFrame + + Parameters + ---------- + where : date or array of dates + subset : string or list of strings, default None + if not None use these columns for NaN propagation + + Notes + ----- + Dates are assumed to be sorted + Raises if this is not the case + + Returns + ------- + where is scalar + + - value or NaN if input is Series + - Series if input is DataFrame + + where is Index: same shape object as input + + See Also + -------- + merge_asof + + Examples + -------- + >>> import pandas as pd + >>> from datetime import datetime + + >>> names = ['curupira', 'saci', 'boitata', 'tupa', float('NaN'), 'cuca'] + >>> dates = [datetime.strptime('20130101', '%Y%m%d'), + ... datetime.strptime('20140101', '%Y%m%d'), + ... datetime.strptime('20140101', '%Y%m%d'), + ... datetime.strptime('20150101', '%Y%m%d'), + ... datetime.strptime('20150101', '%Y%m%d'), + ... datetime.strptime('20160101', '%Y%m%d')] + >>> mySeries = pd.Series(data=names, index=dates) + >>> mySeries.asof(datetime.strptime('20150102', '%Y%m%d')) + `tupa` + >>> mySeries.asof(datetime.strptime('20190201', '%Y%m%d')) + `cuca`` + >>> mySeries.asof(datetime.strptime('20120201', '%Y%m%d')) + nan + """ if isinstance(where, compat.string_types): from pandas import to_datetime From 95a5298b56afd6c7ceab6cc321a25941642099ec Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues Date: Sat, 10 Mar 2018 16:47:59 -0300 Subject: [PATCH 2/2] Fixing the docstring errors --- pandas/core/generic.py | 108 ++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 14a1ec2ee0d25..bc3c7d354a901 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5400,62 +5400,60 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, # Timeseries methods Methods def asof(self, where, subset=None): - """ - Take the last row without any NaN - - Or the last row without - NaN considering only the subset of columns in the case of a DataFrame - - .. versionadded:: 0.19.0 For DataFrame - - If there is no good value, NaN is returned for a Series - a Series of NaN values for a DataFrame - - Parameters - ---------- - where : date or array of dates - subset : string or list of strings, default None - if not None use these columns for NaN propagation - - Notes - ----- - Dates are assumed to be sorted - Raises if this is not the case - - Returns - ------- - where is scalar - - - value or NaN if input is Series - - Series if input is DataFrame - - where is Index: same shape object as input - - See Also - -------- - merge_asof - - Examples - -------- - >>> import pandas as pd - >>> from datetime import datetime - - >>> names = ['curupira', 'saci', 'boitata', 'tupa', float('NaN'), 'cuca'] - >>> dates = [datetime.strptime('20130101', '%Y%m%d'), - ... datetime.strptime('20140101', '%Y%m%d'), - ... datetime.strptime('20140101', '%Y%m%d'), - ... datetime.strptime('20150101', '%Y%m%d'), - ... datetime.strptime('20150101', '%Y%m%d'), - ... datetime.strptime('20160101', '%Y%m%d')] - >>> mySeries = pd.Series(data=names, index=dates) - >>> mySeries.asof(datetime.strptime('20150102', '%Y%m%d')) - `tupa` - >>> mySeries.asof(datetime.strptime('20190201', '%Y%m%d')) - `cuca`` - >>> mySeries.asof(datetime.strptime('20120201', '%Y%m%d')) - nan - """ + """ + Take the last row without any NaN. + + Or the last row without NaN considering only the subset of columns in the case of a DataFrame. + If there is no matched value, NaN is returned for a Series a Series of NaN values for a DataFrame. + + .. versionadded:: 0.19.0 For DataFrame. + + Parameters + ---------- + where : datetime + Date or array of dates. + subset : str + String or list of strings, default None if not None use these columns for NaN propagation. + + Notes + ----- + Dates are assumed to be sorted. + Raises if this is not the case. + + Returns + ------- + where is scalar + + - value or NaN if input is Series. + - Series if input is DataFrame. + + where is Index: same shape object as input. + + See Also + -------- + merge_asof : Perform an asof merge. This is similar to a left-join except that we match on nearest key rather than equal keys. + Examples + -------- + >>> import pandas as pd + >>> from datetime import datetime + + >>> names = ['curupira', 'saci', 'boitata', 'tupa', float('NaN'), 'cuca'] + >>> dates = [datetime.strptime('20130101', '%Y%m%d'), + ... datetime.strptime('20140101', '%Y%m%d'), + ... datetime.strptime('20140101', '%Y%m%d'), + ... datetime.strptime('20150101', '%Y%m%d'), + ... datetime.strptime('20150101', '%Y%m%d'), + ... datetime.strptime('20160101', '%Y%m%d')] + >>> mySeries = pd.Series(data=names, index=dates) + >>> mySeries.asof(datetime.strptime('20150102', '%Y%m%d')) + 'tupa' + >>> mySeries.asof(datetime.strptime('20190201', '%Y%m%d')) + 'cuca' + >>> mySeries.asof(datetime.strptime('20120201', '%Y%m%d')) + nan + """ + if isinstance(where, compat.string_types): from pandas import to_datetime where = to_datetime(where)