Skip to content

Commit 7943bcb

Browse files
committed
Expand tests for pandas-dev#17965 to various datetimelikes
1 parent 95140e6 commit 7943bcb

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

doc/source/whatsnew/v0.21.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Bug Fixes
6161
- Bug in :class:`DatetimeIndex` subtracting datetimelike from DatetimeIndex could fail to overflow (:issue:`18020`)
6262
- Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`)
6363
- Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`)
64-
- Bug in ``_libs.index.convert_scalar()`` when comparing datetimes to np.datetime64 (:issue:`17965`)
64+
- Bug in ``_libs.index.convert_scalar()``: Comparison between ``datetime64[ns]`` series and ``datetimelike`` (:issue:`17965`)
6565

6666
Conversion
6767
^^^^^^^^^^

pandas/_libs/src/datetime/np_datetime_strings.c

+2
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,14 @@ int parse_iso_8601_datetime(char *str, int len, PANDAS_DATETIMEUNIT unit,
509509

510510
/* Skip leading whitespace */
511511
while (sublen > 0 && isspace(*substr)) {
512+
PyErr_Warn(PyExc_Warning, "leading whitespace skipped");
512513
++substr;
513514
--sublen;
514515
}
515516

516517
/* Leading '-' sign for negative year */
517518
if (*substr == '-') {
519+
PyErr_Warn(PyExc_Warning, "leading negative sign");
518520
++substr;
519521
--sublen;
520522
}

pandas/tests/indexes/datetimes/test_partial_slicing.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from datetime import datetime
66
import numpy as np
77
import pandas as pd
8+
from itertools import product
9+
import operator as op
810

911
from pandas import (DatetimeIndex, Series, DataFrame,
1012
date_range, Index, Timedelta, Timestamp)
@@ -331,8 +333,22 @@ def test_loc_datetime_length_one(self):
331333
result = df.loc['2016-10-01T00:00:00':]
332334
tm.assert_frame_equal(result, df)
333335

334-
def test_comparison_to_datetime64(self):
335-
# GH issue #17965
336-
df = DataFrame({'dates': date_range('2000-01-01', '2000-01-05')})
337-
date = df['dates'].unique()[0]
338-
tm.assert_frame_equal(df.loc[df['dates'] == date], df.iloc[:1])
336+
comparisonTS = Timestamp('20130101')
337+
338+
@pytest.mark.parametrize('datetimelike,opExp', product(
339+
[comparisonTS, comparisonTS.to_pydatetime(),
340+
comparisonTS.to_pydatetime().date(), comparisonTS.to_datetime64()],
341+
[(op.lt, [True, False, False, False]),
342+
(op.le, [True, True, False, False]),
343+
(op.eq, [False, True, False, False]),
344+
(op.gt, [False, False, False, True])]))
345+
def test_selection_by_datetimelike(self, datetimelike, opExp):
346+
# GH issue #17965, test for ability to compare datetime64[ns] columns
347+
# to datetimelike
348+
op, exp = opExp
349+
df = DataFrame({'A': [pd.Timestamp('20120101'),
350+
pd.Timestamp('20130101'),
351+
np.nan, pd.Timestamp('20130103')]})
352+
result = op(df.A, datetimelike)
353+
expected = Series(exp, name='A')
354+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)