Skip to content

Commit ace22e0

Browse files
authored
Merge branch 'master' into tslibs-parsing
2 parents 6db3e3c + fa557f7 commit ace22e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+632
-309
lines changed

doc/source/api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ Style Application
20622062

20632063
Styler.apply
20642064
Styler.applymap
2065+
Styler.where
20652066
Styler.format
20662067
Styler.set_precision
20672068
Styler.set_table_styles

doc/source/io.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -4515,8 +4515,7 @@ See the documentation for `pyarrow <http://arrow.apache.org/docs/python/>`__ and
45154515
'd': np.arange(4.0, 7.0, dtype='float64'),
45164516
'e': [True, False, True],
45174517
'f': pd.date_range('20130101', periods=3),
4518-
'g': pd.date_range('20130101', periods=3, tz='US/Eastern'),
4519-
'h': pd.date_range('20130101', periods=3, freq='ns')})
4518+
'g': pd.date_range('20130101', periods=3, tz='US/Eastern')})
45204519
45214520
df
45224521
df.dtypes

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,7 @@ Reshaping
17051705
- Bug in ``pd.concat()`` in which concatenating with an empty dataframe with ``join='inner'`` was being improperly handled (:issue:`15328`)
17061706
- Bug with ``sort=True`` in ``DataFrame.join`` and ``pd.merge`` when joining on indexes (:issue:`15582`)
17071707
- Bug in ``DataFrame.nsmallest`` and ``DataFrame.nlargest`` where identical values resulted in duplicated rows (:issue:`15297`)
1708+
- Bug in :func:`pandas.pivot_table` incorrectly raising ``UnicodeError`` when passing unicode input for ```margins`` keyword (:issue:`13292`)
17081709

17091710
Numeric
17101711
^^^^^^^

doc/source/whatsnew/v0.21.0.txt

+52-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Other Enhancements
112112
- `read_*` methods can now infer compression from non-string paths, such as ``pathlib.Path`` objects (:issue:`17206`).
113113
- :func:`pd.read_sas()` now recognizes much more of the most frequently used date (datetime) formats in SAS7BDAT files (:issue:`15871`).
114114
- :func:`DataFrame.items` and :func:`Series.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`)
115+
- :func:`Styler.where` has been implemented. It is as a convenience for :func:`Styler.applymap` and enables simple DataFrame styling on the Jupyter notebook (:issue:`17474`).
115116

116117

117118

@@ -187,6 +188,53 @@ the target. Now, a ``ValueError`` will be raised when such an input is passed in
187188
...
188189
ValueError: Cannot operate inplace if there is no assignment
189190

191+
.. _whatsnew_0210.api_breaking.iteration_scalars:
192+
193+
Iteration of Series/Index will now return Python scalars
194+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195+
196+
Previously, when using certain iteration methods for a ``Series`` with dtype ``int`` or ``float``, you would receive a ``numpy`` scalar, e.g. a ``np.int64``, rather than a Python ``int``. Issue (:issue:`10904`) corrected this for ``Series.tolist()`` and ``list(Series)``. This change makes all iteration methods consistent, in particular, for ``__iter__()`` and ``.map()``; note that this only affects int/float dtypes. (:issue:`13236`, :issue:`13258`, :issue:`14216`).
197+
198+
.. ipython:: python
199+
200+
s = pd.Series([1, 2, 3])
201+
s
202+
203+
Previously:
204+
205+
.. code-block:: ipython
206+
207+
In [2]: type(list(s)[0])
208+
Out[2]: numpy.int64
209+
210+
New Behaviour:
211+
212+
.. ipython:: python
213+
214+
type(list(s)[0])
215+
216+
Furthermore this will now correctly box the results of iteration for :func:`DataFrame.to_dict` as well.
217+
218+
.. ipython:: ipython
219+
220+
d = {'a':[1], 'b':['b']}
221+
df = pd,DataFrame(d)
222+
223+
Previously:
224+
225+
.. code-block:: ipython
226+
227+
In [8]: type(df.to_dict()['a'][0])
228+
Out[8]: numpy.int64
229+
230+
New Behaviour:
231+
232+
.. ipython:: python
233+
234+
type(df.to_dict()['a'][0])
235+
236+
.. _whatsnew_0210.api_breaking.dtype_conversions:
237+
190238
Dtype Conversions
191239
^^^^^^^^^^^^^^^^^
192240

@@ -340,6 +388,8 @@ Deprecations
340388

341389
- ``pd.options.html.border`` has been deprecated in favor of ``pd.options.display.html.border`` (:issue:`15793`).
342390

391+
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).
392+
343393
.. _whatsnew_0210.prior_deprecations:
344394

345395
Removal of prior version deprecations/changes
@@ -411,6 +461,7 @@ I/O
411461
- Bug in :func:`read_csv` when called with a single-element list ``header`` would return a ``DataFrame`` of all NaN values (:issue:`7757`)
412462
- Bug in :func:`read_stata` where value labels could not be read when using an iterator (:issue:`16923`)
413463
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
464+
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
414465

415466
Plotting
416467
^^^^^^^^
@@ -475,4 +526,4 @@ Other
475526
^^^^^
476527
- Bug in :func:`eval` where the ``inplace`` parameter was being incorrectly handled (:issue:`16732`)
477528
- Several ``NaT`` method docstrings (e.g. :func:`NaT.ctime`) were incorrect (:issue:`17327`)
478-
- The documentation has had references to versions < v0.16 removed and cleaned up (:issue:`17442`, :issue:`17442` & :issue:`#17404`)
529+
- The documentation has had references to versions < v0.17 removed and cleaned up (:issue:`17442`, :issue:`17442`, :issue:`17404` & :issue:`17504`)

pandas/_libs/index.pyx

+3-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cimport tslib
1717

1818
from hashtable cimport HashTable
1919

20+
from tslibs.timezones cimport is_utc, get_utcoffset
2021
from pandas._libs import tslib, algos, hashtable as _hash
2122
from pandas._libs.tslib import Timestamp, Timedelta
2223
from datetime import datetime, timedelta
@@ -32,9 +33,6 @@ cdef extern from "datetime.h":
3233

3334
cdef int64_t iNaT = util.get_nat()
3435

35-
from dateutil.tz import tzutc as _du_utc
36-
import pytz
37-
UTC = pytz.utc
3836

3937
PyDateTime_IMPORT
4038

@@ -553,15 +551,12 @@ cdef inline _to_i8(object val):
553551
tzinfo = getattr(val, 'tzinfo', None)
554552
# Save the original date value so we can get the utcoffset from it.
555553
ival = _pydatetime_to_dts(val, &dts)
556-
if tzinfo is not None and not _is_utc(tzinfo):
557-
offset = tslib._get_utcoffset(tzinfo, val)
554+
if tzinfo is not None and not is_utc(tzinfo):
555+
offset = get_utcoffset(tzinfo, val)
558556
ival -= tslib._delta_to_nanoseconds(offset)
559557
return ival
560558
return val
561559

562-
cdef inline bint _is_utc(object tz):
563-
return tz is UTC or isinstance(tz, _du_utc)
564-
565560

566561
cdef class MultiIndexObjectEngine(ObjectEngine):
567562
"""

pandas/_libs/period.pyx

+8-9
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ from util cimport is_period_object, is_string_object
3333
from lib cimport is_null_datetimelike, is_period
3434
from pandas._libs import tslib, lib
3535
from pandas._libs.tslib import (Timedelta, Timestamp, iNaT,
36-
NaT, _get_utcoffset)
36+
NaT)
37+
from tslibs.timezones cimport is_utc, is_tzlocal, get_utcoffset
3738
from tslib cimport (
3839
maybe_get_tz,
39-
_is_utc,
40-
_is_tzlocal,
4140
_get_dst_info,
4241
_nat_scalar_rules)
4342

@@ -534,23 +533,23 @@ cdef _reso_local(ndarray[int64_t] stamps, object tz):
534533
ndarray[int64_t] trans, deltas, pos
535534
pandas_datetimestruct dts
536535

537-
if _is_utc(tz):
536+
if is_utc(tz):
538537
for i in range(n):
539538
if stamps[i] == NPY_NAT:
540539
continue
541540
pandas_datetime_to_datetimestruct(stamps[i], PANDAS_FR_ns, &dts)
542541
curr_reso = _reso_stamp(&dts)
543542
if curr_reso < reso:
544543
reso = curr_reso
545-
elif _is_tzlocal(tz):
544+
elif is_tzlocal(tz):
546545
for i in range(n):
547546
if stamps[i] == NPY_NAT:
548547
continue
549548
pandas_datetime_to_datetimestruct(stamps[i], PANDAS_FR_ns,
550549
&dts)
551550
dt = datetime(dts.year, dts.month, dts.day, dts.hour,
552551
dts.min, dts.sec, dts.us, tz)
553-
delta = int(_get_utcoffset(tz, dt).total_seconds()) * 1000000000
552+
delta = int(get_utcoffset(tz, dt).total_seconds()) * 1000000000
554553
pandas_datetime_to_datetimestruct(stamps[i] + delta,
555554
PANDAS_FR_ns, &dts)
556555
curr_reso = _reso_stamp(&dts)
@@ -598,7 +597,7 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
598597
ndarray[int64_t] trans, deltas, pos
599598
pandas_datetimestruct dts
600599

601-
if _is_utc(tz):
600+
if is_utc(tz):
602601
for i in range(n):
603602
if stamps[i] == NPY_NAT:
604603
result[i] = NPY_NAT
@@ -608,7 +607,7 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
608607
dts.hour, dts.min, dts.sec,
609608
dts.us, dts.ps, freq)
610609

611-
elif _is_tzlocal(tz):
610+
elif is_tzlocal(tz):
612611
for i in range(n):
613612
if stamps[i] == NPY_NAT:
614613
result[i] = NPY_NAT
@@ -617,7 +616,7 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
617616
&dts)
618617
dt = datetime(dts.year, dts.month, dts.day, dts.hour,
619618
dts.min, dts.sec, dts.us, tz)
620-
delta = int(_get_utcoffset(tz, dt).total_seconds()) * 1000000000
619+
delta = int(get_utcoffset(tz, dt).total_seconds()) * 1000000000
621620
pandas_datetime_to_datetimestruct(stamps[i] + delta,
622621
PANDAS_FR_ns, &dts)
623622
result[i] = get_period_ordinal(dts.year, dts.month, dts.day,

pandas/_libs/src/inference.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import sys
22
from decimal import Decimal
33
cimport util
44
cimport cython
5-
from tslib import NaT, get_timezone
5+
from tslib import NaT
6+
from tslibs.timezones cimport get_timezone
67
from datetime import datetime, timedelta
78
iNaT = util.get_nat()
89

pandas/_libs/tslib.pxd

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ from numpy cimport ndarray, int64_t
33
cdef convert_to_tsobject(object, object, object, bint, bint)
44
cpdef convert_to_timedelta64(object, object)
55
cpdef object maybe_get_tz(object)
6-
cdef bint _is_utc(object)
7-
cdef bint _is_tzlocal(object)
86
cdef object _get_dst_info(object)
97
cdef bint _nat_scalar_rules[6]
108
cdef bint _check_all_nulls(obj)

0 commit comments

Comments
 (0)