Skip to content

Commit 5ac441b

Browse files
Merge remote-tracking branch 'upstream/master' into GenericArrayFormatter-2
2 parents 4b60e4b + 181f972 commit 5ac441b

21 files changed

+547
-383
lines changed

doc/source/user_guide/cookbook.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ Option 1: pass rows explicitly to skip rows
10451045

10461046
.. ipython:: python
10471047
1048-
from pandas.compat import StringIO
1048+
from io import StringIO
10491049
10501050
pd.read_csv(StringIO(data), sep=';', skiprows=[11, 12],
10511051
index_col=0, parse_dates=True, header=10)

doc/source/user_guide/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ usecols : list-like or callable, default ``None``
137137

138138
.. ipython:: python
139139
140-
from pandas.compat import StringIO, BytesIO
140+
from io import StringIO, BytesIO
141141
data = ('col1,col2,col3\n'
142142
'a,b,1\n'
143143
'a,b,2\n'

doc/source/whatsnew/v0.19.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ default of the index) in a DataFrame.
192192
.. ipython:: python
193193
:suppress:
194194
195-
from pandas.compat import StringIO
195+
from io import StringIO
196196
197197
:ref:`Duplicate column names <io.dupe_names>` are now supported in :func:`read_csv` whether
198198
they are in the file or passed in as the ``names`` parameter (:issue:`7160`, :issue:`9424`)

doc/source/whatsnew/v0.20.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fixed-width text files and :func:`read_excel` for parsing Excel files, now accep
119119
.. ipython:: python
120120
:suppress:
121121
122-
from pandas.compat import StringIO
122+
from io import StringIO
123123
124124
.. ipython:: python
125125

doc/source/whatsnew/v0.21.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ be strings.
194194
.. ipython:: python
195195
:suppress:
196196
197-
from pandas.compat import StringIO
197+
from io import StringIO
198198
199199
.. ipython:: python
200200

doc/source/whatsnew/v0.24.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ missing indicator, ``np.nan``. (:issue:`20377`)
567567
.. ipython:: python
568568
:suppress:
569569
570-
from pandas.compat import StringIO
570+
from pandas.io import StringIO
571571
572572
*Previous Behavior*:
573573

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ Sparse
407407
Other
408408
^^^^^
409409

410+
- Improved :class:`Timestamp` type checking in various datetime functions to prevent exceptions when using a subclassed `datetime` (:issue:`25851`)
410411
- Bug in :class:`Series` and :class:`DataFrame` repr where ``np.datetime64('NaT')`` and ``np.timedelta64('NaT')`` with ``dtype=object`` would be represented as ``NaN`` (:issue:`25445`)
411412
-
412413
-

pandas/_libs/tslib.pyx

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import cython
33

44
from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
5-
PyDateTime_CheckExact,
65
PyDateTime_IMPORT,
76
timedelta, datetime, date, time)
87
# import datetime C API
@@ -19,6 +18,7 @@ import pytz
1918
from pandas._libs.util cimport (
2019
is_integer_object, is_float_object, is_datetime64_object)
2120

21+
from pandas._libs.tslibs.c_timestamp cimport _Timestamp
2222

2323
from pandas._libs.tslibs.np_datetime cimport (
2424
check_dts_bounds, npy_datetimestruct, _string_to_dts, dt64_to_dtstruct,
@@ -539,8 +539,7 @@ cpdef array_to_datetime(ndarray[object] values, str errors='raise',
539539
'datetime64 unless utc=True')
540540
else:
541541
iresult[i] = pydatetime_to_dt64(val, &dts)
542-
if not PyDateTime_CheckExact(val):
543-
# i.e. a Timestamp object
542+
if isinstance(val, _Timestamp):
544543
iresult[i] += val.nanosecond
545544
check_dts_bounds(&dts)
546545

pandas/_libs/tslibs/c_timestamp.pxd

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from cpython.datetime cimport datetime
4+
5+
from numpy cimport int64_t
6+
7+
cdef class _Timestamp(datetime):
8+
cdef readonly:
9+
int64_t value, nanosecond
10+
object freq
11+
list _date_attributes
12+
cpdef bint _get_start_end_field(self, str field)
13+
cpdef _get_date_name_field(self, object field, object locale)
14+
cdef int64_t _maybe_convert_value_to_local(self)
15+
cpdef to_datetime64(self)
16+
cdef _assert_tzawareness_compat(_Timestamp self, datetime other)
17+
cpdef datetime to_pydatetime(_Timestamp self, bint warn=*)
18+
cdef bint _compare_outside_nanorange(_Timestamp self, datetime other,
19+
int op) except -1

0 commit comments

Comments
 (0)