Skip to content

Commit ff7c06c

Browse files
committed
Squashed commit of the following:
commit 11a0d93 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 14:26:34 2018 -0500 typerror commit a0cd5e7 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 14:25:38 2018 -0500 TypeError for Series commit 2247461 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 13:29:29 2018 -0500 Test op(Series[EA], EA]) commit c9fe5d3 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 13:21:33 2018 -0500 make strict commit 7ef697c Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 13:14:52 2018 -0500 Use super commit 35d4213 Merge: 0671e7d ee80803 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 13:11:05 2018 -0500 Merge remote-tracking branch 'upstream/master' into ea-divmod commit ee80803 Author: Matthew Roeschke <[email protected]> Date: Wed Oct 3 08:25:44 2018 -0700 BUG: Correctly weekly resample over DST (pandas-dev#22941) * test resample fix * move the localization until needed * BUG: Correctly weekly resample over DST * Move whatsnew to new section commit fea27f0 Author: Tom Augspurger <[email protected]> Date: Wed Oct 3 08:49:44 2018 -0500 CI: pin moto to 1.3.4 (pandas-dev#22959) commit 15d32bb Author: jbrockmendel <[email protected]> Date: Wed Oct 3 04:32:35 2018 -0700 [CLN] Dispatch (some) Frame ops to Series, avoiding _data.eval (pandas-dev#22019) * avoid casting to object dtype in mixed-type frames * Dispatch to Series ops in _combine_match_columns * comment * docstring * flake8 fixup * dont bother with try_cast_result * revert non-central change * simplify * revert try_cast_results * revert non-central changes * Fixup typo syntaxerror * simplify assertion * use dispatch_to_series in combine_match_columns * Pass unwrapped op where appropriate * catch correct error * whatsnew note * comment * whatsnew section * remove unnecessary tester * doc fixup commit 3e3256b Author: alimcmaster1 <[email protected]> Date: Wed Oct 3 12:23:22 2018 +0100 Allow passing a mask to NanOps (pandas-dev#22865) commit e756e99 Author: jbrockmendel <[email protected]> Date: Wed Oct 3 02:19:27 2018 -0700 CLN: Use is_period_dtype instead of ABCPeriodIndex checks (pandas-dev#22958) commit 03181f0 Author: Wenhuan <[email protected]> Date: Wed Oct 3 15:28:07 2018 +0800 BUG: fix Series(extension array) + extension array values addition (pandas-dev#22479) commit 04ea51d Author: Joris Van den Bossche <[email protected]> Date: Wed Oct 3 09:24:36 2018 +0200 CLN: small clean-up of IntervalIndex (pandas-dev#22956) commit b0f9a10 Author: Tony Tao <[email protected]> Date: Tue Oct 2 19:01:08 2018 -0500 DOC GH22893 Fix docstring of groupby in pandas/core/generic.py (pandas-dev#22920) commit 08ecba8 Author: jbrockmendel <[email protected]> Date: Tue Oct 2 14:22:53 2018 -0700 BUG: fix DataFrame+DataFrame op with timedelta64 dtype (pandas-dev#22696) commit c44bad2 Author: Pamela Wu <[email protected]> Date: Tue Oct 2 17:16:25 2018 -0400 CLN GH22873 Replace base excepts in pandas/core (pandas-dev#22901) commit 8e749a3 Author: Pamela Wu <[email protected]> Date: Tue Oct 2 17:14:48 2018 -0400 CLN GH22874 replace bare excepts in pandas/io/pytables.py (pandas-dev#22919) commit 1102a33 Author: Joris Van den Bossche <[email protected]> Date: Tue Oct 2 22:31:36 2018 +0200 DOC/CLN: clean-up shared_docs in generic.py (pandas-dev#20074) commit 9caf048 Author: Tom Augspurger <[email protected]> Date: Tue Oct 2 13:25:22 2018 -0500 CI: change windows vm image (pandas-dev#22948) commit 0671e7d Author: Tom Augspurger <[email protected]> Date: Tue Oct 2 11:10:42 2018 -0500 Fixup commit 1b4261f Merge: c92a4a8 1d9f76c Author: Tom Augspurger <[email protected]> Date: Tue Oct 2 10:58:43 2018 -0500 Merge remote-tracking branch 'upstream/master' into ea-divmod commit 1d9f76c Author: Joris Van den Bossche <[email protected]> Date: Tue Oct 2 17:11:11 2018 +0200 CLN: remove Index._to_embed (pandas-dev#22879) * CLN: remove Index._to_embed * pep8 commit 6247da0 Author: Tom Augspurger <[email protected]> Date: Tue Oct 2 08:50:41 2018 -0500 Provide default implementation for `data_repated` (pandas-dev#22935) commit c92a4a8 Author: Tom Augspurger <[email protected]> Date: Mon Oct 1 16:56:15 2018 -0500 Update old test commit 52538fa Author: Tom Augspurger <[email protected]> Date: Mon Oct 1 16:51:48 2018 -0500 BUG: divmod return type commit 5ce06b5 Author: Matthew Roeschke <[email protected]> Date: Mon Oct 1 14:22:20 2018 -0700 BUG: to_datetime preserves name of Index argument in the result (pandas-dev#22918) * BUG: to_datetime preserves name of Index argument in the result * correct test
1 parent 012be1c commit ff7c06c

Some content is hidden

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

41 files changed

+849
-319
lines changed

ci/travis-27.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies:
4444
# universal
4545
- pytest
4646
- pytest-xdist
47-
- moto
47+
- moto==1.3.4
4848
- hypothesis>=3.58.0
4949
- pip:
5050
- backports.lzma

doc/source/extending.rst

+12-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,18 @@ your ``MyExtensionArray`` class, as follows:
160160
MyExtensionArray._add_arithmetic_ops()
161161
MyExtensionArray._add_comparison_ops()
162162
163-
Note that since ``pandas`` automatically calls the underlying operator on each
164-
element one-by-one, this might not be as performant as implementing your own
165-
version of the associated operators directly on the ``ExtensionArray``.
163+
164+
.. note::
165+
166+
Since ``pandas`` automatically calls the underlying operator on each
167+
element one-by-one, this might not be as performant as implementing your own
168+
version of the associated operators directly on the ``ExtensionArray``.
169+
170+
This implementation will try to reconstruct a new ``ExtensionArray`` with the
171+
result of the element-wise operation. Whether or not that succeeds depends on
172+
whether the operation returns a result that's valid for the ``ExtensionArray``.
173+
If an ``ExtensionArray`` cannot be reconstructed, a list containing the scalars
174+
returned instead.
166175

167176
.. _extending.extension.testing:
168177

doc/source/whatsnew/v0.24.0.txt

+31-2
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,35 @@ Current Behavior:
579579
...
580580
OverflowError: Trying to coerce negative values to unsigned integers
581581

582+
.. _whatsnew_0240.api.crosstab_dtypes
583+
584+
Crosstab Preserves Dtypes
585+
^^^^^^^^^^^^^^^^^^^^^^^^^
586+
587+
:func:`crosstab` will preserve now dtypes in some cases that previously would
588+
cast from integer dtype to floating dtype (:issue:`22019`)
589+
590+
Previous Behavior:
591+
592+
.. code-block:: ipython
593+
594+
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
595+
...: 'c': [1, 1, np.nan, 1, 1]})
596+
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
597+
Out[4]:
598+
b 3 4
599+
a
600+
1 0.5 0.0
601+
2 0.5 1.0
602+
603+
Current Behavior:
604+
605+
.. code-block:: ipython
606+
607+
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
608+
...: 'c': [1, 1, np.nan, 1, 1]})
609+
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
610+
582611
Datetimelike API Changes
583612
^^^^^^^^^^^^^^^^^^^^^^^^
584613

@@ -713,7 +742,7 @@ Timedelta
713742
- Bug in :class:`Index` with numeric dtype when multiplying or dividing an array with dtype ``timedelta64`` (:issue:`22390`)
714743
- Bug in :class:`TimedeltaIndex` incorrectly allowing indexing with ``Timestamp`` object (:issue:`20464`)
715744
- Fixed bug where subtracting :class:`Timedelta` from an object-dtyped array would raise ``TypeError`` (:issue:`21980`)
716-
-
745+
- Fixed bug in adding a :class:`DataFrame` with all-`timedelta64[ns]` dtypes to a :class:`DataFrame` with all-integer dtypes returning incorrect results instead of raising ``TypeError`` (:issue:`22696`)
717746
-
718747

719748
Timezones
@@ -841,6 +870,7 @@ Groupby/Resample/Rolling
841870
- Bug in :meth:`Resampler.asfreq` when frequency of ``TimedeltaIndex`` is a subperiod of a new frequency (:issue:`13022`).
842871
- Bug in :meth:`SeriesGroupBy.mean` when values were integral but could not fit inside of int64, overflowing instead. (:issue:`22487`)
843872
- :func:`RollingGroupby.agg` and :func:`ExpandingGroupby.agg` now support multiple aggregation functions as parameters (:issue:`15072`)
873+
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` when resampling by a weekly offset (``'W'``) across a DST transition (:issue:`9119`, :issue:`21459`)
844874

845875
Sparse
846876
^^^^^^
@@ -881,4 +911,3 @@ Other
881911
- :meth:`DataFrame.nlargest` and :meth:`DataFrame.nsmallest` now returns the correct n values when keep != 'all' also when tied on the first columns (:issue:`22752`)
882912
- :meth:`~pandas.io.formats.style.Styler.bar` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` and setting clipping range with ``vmin`` and ``vmax`` (:issue:`21548` and :issue:`21526`). ``NaN`` values are also handled properly.
883913
- Logical operations ``&, |, ^`` between :class:`Series` and :class:`Index` will no longer raise ``ValueError`` (:issue:`22092`)
884-
-

pandas/core/arrays/base.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,18 @@ def convert_values(param):
775775
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
776776

777777
if coerce_to_dtype:
778-
try:
779-
res = self._from_sequence(res)
780-
except TypeError:
781-
pass
778+
if op.__name__ in {'divmod', 'rdivmod'}:
779+
try:
780+
a, b = zip(*res)
781+
res = (self._from_sequence(a),
782+
self._from_sequence(b))
783+
except TypeError:
784+
pass
785+
else:
786+
try:
787+
res = self._from_sequence(res)
788+
except TypeError:
789+
pass
782790

783791
return res
784792

pandas/core/arrays/interval.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ class IntervalArray(IntervalMixin, ExtensionArray):
108108
_na_value = _fill_value = np.nan
109109

110110
def __new__(cls, data, closed=None, dtype=None, copy=False,
111-
fastpath=False, verify_integrity=True):
112-
113-
if fastpath:
114-
return cls._simple_new(data.left, data.right, closed,
115-
copy=copy, dtype=dtype,
116-
verify_integrity=False)
111+
verify_integrity=True):
117112

118113
if isinstance(data, ABCSeries) and is_interval_dtype(data):
119114
data = data.values

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def asfreq(self, freq=None, how='E'):
539539
if self.hasnans:
540540
new_data[self._isnan] = iNaT
541541

542-
return self._simple_new(new_data, freq=freq)
542+
return self._shallow_copy(new_data, freq=freq)
543543

544544
# ------------------------------------------------------------------
545545
# Arithmetic Methods

pandas/core/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def visit_Subscript(self, node, **kwargs):
411411
slobj = self.visit(node.slice)
412412
try:
413413
value = value.value
414-
except:
414+
except AttributeError:
415415
pass
416416

417417
try:

pandas/core/dtypes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def is_timedelta64_dtype(arr_or_dtype):
468468
return False
469469
try:
470470
tipo = _get_dtype_type(arr_or_dtype)
471-
except:
471+
except (TypeError, ValueError, SyntaxError):
472472
return False
473473
return issubclass(tipo, np.timedelta64)
474474

pandas/core/dtypes/dtypes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ def construct_from_string(cls, string):
360360
try:
361361
if string == 'category':
362362
return cls()
363-
except:
363+
else:
364+
raise TypeError("cannot construct a CategoricalDtype")
365+
except AttributeError:
364366
pass
365367

366-
raise TypeError("cannot construct a CategoricalDtype")
367-
368368
@staticmethod
369369
def validate_ordered(ordered):
370370
"""
@@ -514,7 +514,7 @@ def __new__(cls, unit=None, tz=None):
514514
if m is not None:
515515
unit = m.groupdict()['unit']
516516
tz = m.groupdict()['tz']
517-
except:
517+
except TypeError:
518518
raise ValueError("could not construct DatetimeTZDtype")
519519

520520
elif isinstance(unit, compat.string_types):

pandas/core/frame.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,7 @@ def _ensure_valid_index(self, value):
32603260
if not len(self.index) and is_list_like(value):
32613261
try:
32623262
value = Series(value)
3263-
except:
3263+
except (ValueError, NotImplementedError, TypeError):
32643264
raise ValueError('Cannot set a frame with no defined index '
32653265
'and a value that cannot be converted to a '
32663266
'Series')
@@ -3629,7 +3629,8 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
36293629
fill_axis=fill_axis,
36303630
broadcast_axis=broadcast_axis)
36313631

3632-
@Appender(_shared_docs['reindex'] % _shared_doc_kwargs)
3632+
@Substitution(**_shared_doc_kwargs)
3633+
@Appender(NDFrame.reindex.__doc__)
36333634
@rewrite_axis_style_signature('labels', [('method', None),
36343635
('copy', True),
36353636
('level', None),
@@ -4479,7 +4480,8 @@ def f(vals):
44794480
# ----------------------------------------------------------------------
44804481
# Sorting
44814482

4482-
@Appender(_shared_docs['sort_values'] % _shared_doc_kwargs)
4483+
@Substitution(**_shared_doc_kwargs)
4484+
@Appender(NDFrame.sort_values.__doc__)
44834485
def sort_values(self, by, axis=0, ascending=True, inplace=False,
44844486
kind='quicksort', na_position='last'):
44854487
inplace = validate_bool_kwarg(inplace, 'inplace')
@@ -4521,7 +4523,8 @@ def sort_values(self, by, axis=0, ascending=True, inplace=False,
45214523
else:
45224524
return self._constructor(new_data).__finalize__(self)
45234525

4524-
@Appender(_shared_docs['sort_index'] % _shared_doc_kwargs)
4526+
@Substitution(**_shared_doc_kwargs)
4527+
@Appender(NDFrame.sort_index.__doc__)
45254528
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
45264529
kind='quicksort', na_position='last', sort_remaining=True,
45274530
by=None):
@@ -4886,7 +4889,7 @@ def _arith_op(left, right):
48864889
left, right = ops.fill_binop(left, right, fill_value)
48874890
return func(left, right)
48884891

4889-
if this._is_mixed_type or other._is_mixed_type:
4892+
if ops.should_series_dispatch(this, other, func):
48904893
# iterate over columns
48914894
return ops.dispatch_to_series(this, other, _arith_op)
48924895
else:
@@ -4896,7 +4899,6 @@ def _arith_op(left, right):
48964899
copy=False)
48974900

48984901
def _combine_match_index(self, other, func, level=None):
4899-
assert isinstance(other, Series)
49004902
left, right = self.align(other, join='outer', axis=0, level=level,
49014903
copy=False)
49024904
assert left.index.equals(right.index)
@@ -4916,11 +4918,7 @@ def _combine_match_columns(self, other, func, level=None, try_cast=True):
49164918
left, right = self.align(other, join='outer', axis=1, level=level,
49174919
copy=False)
49184920
assert left.columns.equals(right.index)
4919-
4920-
new_data = left._data.eval(func=func, other=right,
4921-
axes=[left.columns, self.index],
4922-
try_cast=try_cast)
4923-
return self._constructor(new_data)
4921+
return ops.dispatch_to_series(left, right, func, axis="columns")
49244922

49254923
def _combine_const(self, other, func, errors='raise', try_cast=True):
49264924
if lib.is_scalar(other) or np.ndim(other) == 0:
@@ -7747,7 +7745,7 @@ def convert(v):
77477745
values = np.array([convert(v) for v in values])
77487746
else:
77497747
values = convert(values)
7750-
except:
7748+
except (ValueError, TypeError):
77517749
values = convert(values)
77527750

77537751
else:

0 commit comments

Comments
 (0)