Skip to content

Commit 9403b11

Browse files
committed
DOC: filter the correct warning for unique(key, column)
DOC/CLN: clean up indentation and dispatch on numpy version
1 parent 24102ae commit 9403b11

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed

doc/source/timeseries.rst

+57-43
Original file line numberDiff line numberDiff line change
@@ -930,89 +930,103 @@ They can be both positive and negative.
930930

931931
.. ipython:: python
932932
933-
from datetime import datetime, timedelta
934-
s = Series(date_range('2012-1-1', periods=3, freq='D'))
935-
td = Series([ timedelta(days=i) for i in range(3) ])
936-
df = DataFrame(dict(A = s, B = td))
937-
df
938-
df['C'] = df['A'] + df['B']
939-
df
940-
df.dtypes
941-
942-
s - s.max()
943-
s - datetime(2011,1,1,3,5)
944-
s + timedelta(minutes=5)
933+
from datetime import datetime, timedelta
934+
s = Series(date_range('2012-1-1', periods=3, freq='D'))
935+
td = Series([ timedelta(days=i) for i in range(3) ])
936+
df = DataFrame(dict(A = s, B = td))
937+
df
938+
df['C'] = df['A'] + df['B']
939+
df
940+
df.dtypes
941+
942+
s - s.max()
943+
s - datetime(2011,1,1,3,5)
944+
s + timedelta(minutes=5)
945945
946946
Getting scalar results from a ``timedelta64[ns]`` series
947947

948+
.. ipython:: python
949+
:suppress:
950+
951+
from distutils.version import LooseVersion
952+
948953
.. ipython:: python
949954
950955
y = s - s[0]
951956
y
952-
y.apply(lambda x: x.item().total_seconds())
953-
y.apply(lambda x: x.item().days)
954-
955-
.. note::
956957
957-
These operations are different in numpy 1.6.2 and in numpy >= 1.7. The ``timedelta64[ns]`` scalar
958-
type in 1.6.2 is much like a ``datetime.timedelta``, while in 1.7 it is a nanosecond based integer.
959-
A future version of pandas will make this transparent.
958+
if LooseVersion(np.__version__) <= '1.6.2':
959+
y.apply(lambda x: x.item().total_seconds())
960+
y.apply(lambda x: x.item().days)
961+
else:
962+
y.apply(lambda x: x / np.timedelta64(1, 's'))
963+
y.apply(lambda x: x / np.timedelta64(1, 'D'))
964+
965+
.. note::
960966

961-
These are the equivalent operation to above in numpy >= 1.7
967+
As you can see from the conditional statement above, these operations are
968+
different in numpy 1.6.2 and in numpy >= 1.7. The ``timedelta64[ns]`` scalar
969+
type in 1.6.2 is much like a ``datetime.timedelta``, while in 1.7 it is a
970+
nanosecond based integer. A future version of pandas will make this
971+
transparent.
962972

963-
``y.apply(lambda x: x.item()/np.timedelta64(1,'s'))``
973+
.. note::
964974

965-
``y.apply(lambda x: x.item()/np.timedelta64(1,'D'))``
975+
In numpy >= 1.7 dividing a ``timedelta64`` array by another ``timedelta64``
976+
array will yield an array with dtype ``np.float64``.
966977

967978
Series of timedeltas with ``NaT`` values are supported
968979

969980
.. ipython:: python
970981
971-
y = s - s.shift()
972-
y
982+
y = s - s.shift()
983+
y
984+
973985
The can be set to ``NaT`` using ``np.nan`` analagously to datetimes
974986

975987
.. ipython:: python
976988
977-
y[1] = np.nan
978-
y
989+
y[1] = np.nan
990+
y
979991
980992
Operands can also appear in a reversed order (a singluar object operated with a Series)
981993

982994
.. ipython:: python
983995
984-
s.max() - s
985-
datetime(2011,1,1,3,5) - s
986-
timedelta(minutes=5) + s
996+
s.max() - s
997+
datetime(2011,1,1,3,5) - s
998+
timedelta(minutes=5) + s
987999
9881000
Some timedelta numeric like operations are supported.
9891001

9901002
.. ipython:: python
9911003
992-
td - timedelta(minutes=5,seconds=5,microseconds=5)
1004+
td - timedelta(minutes=5, seconds=5, microseconds=5)
9931005
9941006
``min, max`` and the corresponding ``idxmin, idxmax`` operations are support on frames
9951007

9961008
.. ipython:: python
9971009
998-
df = DataFrame(dict(A = s - Timestamp('20120101')-timedelta(minutes=5,seconds=5),
999-
B = s - Series(date_range('2012-1-2', periods=3, freq='D'))))
1000-
df
1010+
A = s - Timestamp('20120101') - timedelta(minutes=5, seconds=5)
1011+
B = s - Series(date_range('2012-1-2', periods=3, freq='D'))
10011012
1013+
df = DataFrame(dict(A=A, B=B))
1014+
df
10021015
1003-
df.min()
1004-
df.min(axis=1)
1016+
df.min()
1017+
df.min(axis=1)
10051018
1006-
df.idxmin()
1007-
df.idxmax()
1019+
df.idxmin()
1020+
df.idxmax()
10081021
1009-
``min, max`` operations are support on series, these return a single element ``timedelta64[ns]`` Series (this avoids
1010-
having to deal with numpy timedelta64 issues). ``idxmin, idxmax`` are supported as well.
1022+
``min, max`` operations are support on series, these return a single element
1023+
``timedelta64[ns]`` Series (this avoids having to deal with numpy timedelta64
1024+
issues). ``idxmin, idxmax`` are supported as well.
10111025

10121026
.. ipython:: python
10131027
1014-
df.min().max()
1015-
df.min(axis=1).min()
1028+
df.min().max()
1029+
df.min(axis=1).min()
10161030
1017-
df.min().idxmax()
1018-
df.min(axis=1).idxmin()
1031+
df.min().idxmax()
1032+
df.min(axis=1).idxmin()

doc/source/v0.10.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Retrieving unique values in an indexable or data column.
6969

7070
import warnings
7171
with warnings.catch_warnings():
72-
warnings.simplefilter('ignore', category=DeprecationWarning)
72+
warnings.simplefilter('ignore', category=UserWarning)
7373
store.unique('df','index')
7474
store.unique('df','string')
7575

0 commit comments

Comments
 (0)