Skip to content

Commit 2b86b04

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into tslibs-offsets-years
2 parents 47ede13 + 77f10f0 commit 2b86b04

File tree

6 files changed

+92
-15
lines changed

6 files changed

+92
-15
lines changed

doc/source/whatsnew/v0.21.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Conversion
7373
Indexing
7474
^^^^^^^^
7575

76+
- Bug in a boolean comparison of a ``datetime.datetime`` and a ``datetime64[ns]`` dtype Series (:issue:`17965`)
7677
- Bug where a ``MultiIndex`` with more than a million records was not raising ``AttributeError`` when trying to access a missing attribute (:issue:`18165`)
7778
-
7879
-

pandas/_libs/index.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from hashtable cimport HashTable
1919

2020
from pandas._libs import algos, period as periodlib, hashtable as _hash
2121
from pandas._libs.tslib import Timestamp, Timedelta
22-
from datetime import datetime, timedelta
22+
from datetime import datetime, timedelta, date
2323

2424
from cpython cimport PyTuple_Check, PyList_Check
2525

@@ -549,7 +549,7 @@ cpdef convert_scalar(ndarray arr, object value):
549549
if arr.descr.type_num == NPY_DATETIME:
550550
if isinstance(value, np.ndarray):
551551
pass
552-
elif isinstance(value, datetime):
552+
elif isinstance(value, (datetime, np.datetime64, date)):
553553
return Timestamp(value).value
554554
elif value is None or value != value:
555555
return iNaT

pandas/core/frame.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -4029,15 +4029,30 @@ def combine(self, other, func, fill_value=None, overwrite=True):
40294029
----------
40304030
other : DataFrame
40314031
func : function
4032+
Function that takes two series as inputs and return a Series or a
4033+
scalar
40324034
fill_value : scalar value
40334035
overwrite : boolean, default True
40344036
If True then overwrite values for common keys in the calling frame
40354037
40364038
Returns
40374039
-------
40384040
result : DataFrame
4039-
"""
40404041
4042+
Examples
4043+
--------
4044+
>>> df1 = DataFrame({'A': [0, 0], 'B': [4, 4]})
4045+
>>> df2 = DataFrame({'A': [1, 1], 'B': [3, 3]})
4046+
>>> df1.combine(df2, lambda s1, s2: s1 if s1.sum() < s2.sum() else s2)
4047+
A B
4048+
0 0 3
4049+
1 0 3
4050+
4051+
See Also
4052+
--------
4053+
DataFrame.combine_first : Combine two DataFrame objects and default to
4054+
non-null values in frame calling the method
4055+
"""
40414056
other_idxlen = len(other.index) # save for compare
40424057

40434058
this, other = self.align(other, copy=False)
@@ -4125,16 +4140,24 @@ def combine_first(self, other):
41254140
----------
41264141
other : DataFrame
41274142
4143+
Returns
4144+
-------
4145+
combined : DataFrame
4146+
41284147
Examples
41294148
--------
4130-
a's values prioritized, use values from b to fill holes:
4149+
df1's values prioritized, use values from df2 to fill holes:
41314150
4132-
>>> a.combine_first(b)
4151+
>>> df1 = pd.DataFrame([[1, np.nan]])
4152+
>>> df2 = pd.DataFrame([[3, 4]])
4153+
>>> df1.combine_first(df2)
4154+
0 1
4155+
0 1 4.0
41334156
4134-
4135-
Returns
4136-
-------
4137-
combined : DataFrame
4157+
See Also
4158+
--------
4159+
DataFrame.combine : Perform series-wise operation on two DataFrames
4160+
using a given function
41384161
"""
41394162
import pandas.core.computation.expressions as expressions
41404163

pandas/core/series.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -1361,13 +1361,13 @@ def idxmax(self, axis=None, skipna=True, *args, **kwargs):
13611361

13621362
# ndarray compat
13631363
argmin = deprecate('argmin', idxmin,
1364-
msg="'argmin' is deprecated. Use 'idxmin' instead. "
1364+
msg="'argmin' is deprecated, use 'idxmin' instead. "
13651365
"The behavior of 'argmin' will be corrected to "
13661366
"return the positional minimum in the future. "
13671367
"Use 'series.values.argmin' to get the position of "
13681368
"the minimum now.")
13691369
argmax = deprecate('argmax', idxmax,
1370-
msg="'argmax' is deprecated. Use 'idxmax' instead. "
1370+
msg="'argmax' is deprecated, use 'idxmax' instead. "
13711371
"The behavior of 'argmax' will be corrected to "
13721372
"return the positional maximum in the future. "
13731373
"Use 'series.values.argmax' to get the position of "
@@ -1731,11 +1731,26 @@ def combine(self, other, func, fill_value=np.nan):
17311731
----------
17321732
other : Series or scalar value
17331733
func : function
1734+
Function that takes two scalars as inputs and return a scalar
17341735
fill_value : scalar value
17351736
17361737
Returns
17371738
-------
17381739
result : Series
1740+
1741+
Examples
1742+
--------
1743+
>>> s1 = Series([1, 2])
1744+
>>> s2 = Series([0, 3])
1745+
>>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2)
1746+
0 0
1747+
1 2
1748+
dtype: int64
1749+
1750+
See Also
1751+
--------
1752+
Series.combine_first : Combine Series values, choosing the calling
1753+
Series's values first
17391754
"""
17401755
if isinstance(other, Series):
17411756
new_index = self.index.union(other.index)
@@ -1764,7 +1779,21 @@ def combine_first(self, other):
17641779
17651780
Returns
17661781
-------
1767-
y : Series
1782+
combined : Series
1783+
1784+
Examples
1785+
--------
1786+
>>> s1 = pd.Series([1, np.nan])
1787+
>>> s2 = pd.Series([3, 4])
1788+
>>> s1.combine_first(s2)
1789+
0 1.0
1790+
1 4.0
1791+
dtype: float64
1792+
1793+
See Also
1794+
--------
1795+
Series.combine : Perform elementwise operation on two Series
1796+
using a given function
17681797
"""
17691798
new_index = self.index.union(other.index)
17701799
this = self.reindex(new_index, copy=False)

pandas/tests/indexes/datetimes/test_partial_slicing.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44

5-
from datetime import datetime
5+
from datetime import datetime, date
66
import numpy as np
77
import pandas as pd
8+
import operator as op
89

910
from pandas import (DatetimeIndex, Series, DataFrame,
1011
date_range, Index, Timedelta, Timestamp)
@@ -330,3 +331,21 @@ def test_loc_datetime_length_one(self):
330331

331332
result = df.loc['2016-10-01T00:00:00':]
332333
tm.assert_frame_equal(result, df)
334+
335+
@pytest.mark.parametrize('datetimelike', [
336+
Timestamp('20130101'), datetime(2013, 1, 1),
337+
date(2013, 1, 1), np.datetime64('2013-01-01T00:00', 'ns')])
338+
@pytest.mark.parametrize('op,expected', [
339+
(op.lt, [True, False, False, False]),
340+
(op.le, [True, True, False, False]),
341+
(op.eq, [False, True, False, False]),
342+
(op.gt, [False, False, False, True])])
343+
def test_selection_by_datetimelike(self, datetimelike, op, expected):
344+
# GH issue #17965, test for ability to compare datetime64[ns] columns
345+
# to datetimelike
346+
df = DataFrame({'A': [pd.Timestamp('20120101'),
347+
pd.Timestamp('20130101'),
348+
np.nan, pd.Timestamp('20130103')]})
349+
result = op(df.A, datetimelike)
350+
expected = Series(expected, name='A')
351+
tm.assert_series_equal(result, expected)

pandas/util/_decorators.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import inspect
44
import types
55
import warnings
6-
from textwrap import dedent
6+
from textwrap import dedent, wrap
77
from functools import wraps, update_wrapper
88

99

@@ -29,11 +29,16 @@ def deprecate(name, alternative, alt_name=None, klass=None,
2929

3030
alt_name = alt_name or alternative.__name__
3131
klass = klass or FutureWarning
32-
msg = msg or "{} is deprecated. Use {} instead".format(name, alt_name)
32+
msg = msg or "{} is deprecated, use {} instead".format(name, alt_name)
3333

34+
@wraps(alternative)
3435
def wrapper(*args, **kwargs):
3536
warnings.warn(msg, klass, stacklevel=stacklevel)
3637
return alternative(*args, **kwargs)
38+
39+
if getattr(wrapper, '__doc__', None) is not None:
40+
wrapper.__doc__ = ('\n'.join(wrap(msg, 70)) + '\n'
41+
+ dedent(wrapper.__doc__))
3742
return wrapper
3843

3944

0 commit comments

Comments
 (0)