Skip to content

Commit 159ecf5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into df_set_index_warn
2 parents 6d3dfa1 + 15d32bb commit 159ecf5

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

+772
-378
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
- template: ci/azure/windows.yml
1919
parameters:
2020
name: Windows
21-
vmImage: vs2017-win2017
21+
vmImage: vs2017-win2016
2222
- template: ci/azure/windows-py27.yml
2323
parameters:
2424
name: WindowsPy27
25-
vmImage: vs2017-win2017
25+
vmImage: vs2017-win2016

doc/source/whatsnew/v0.24.0.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,35 @@ Current Behavior:
532532
...
533533
OverflowError: Trying to coerce negative values to unsigned integers
534534

535+
.. _whatsnew_0240.api.crosstab_dtypes
536+
537+
Crosstab Preserves Dtypes
538+
^^^^^^^^^^^^^^^^^^^^^^^^^
539+
540+
:func:`crosstab` will preserve now dtypes in some cases that previously would
541+
cast from integer dtype to floating dtype (:issue:`22019`)
542+
543+
Previous Behavior:
544+
545+
.. code-block:: ipython
546+
547+
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
548+
...: 'c': [1, 1, np.nan, 1, 1]})
549+
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
550+
Out[4]:
551+
b 3 4
552+
a
553+
1 0.5 0.0
554+
2 0.5 1.0
555+
556+
Current Behavior:
557+
558+
.. code-block:: ipython
559+
560+
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
561+
...: 'c': [1, 1, np.nan, 1, 1]})
562+
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
563+
535564
Datetimelike API Changes
536565
^^^^^^^^^^^^^^^^^^^^^^^^
537566

@@ -667,7 +696,7 @@ Timedelta
667696
- Bug in :class:`Index` with numeric dtype when multiplying or dividing an array with dtype ``timedelta64`` (:issue:`22390`)
668697
- Bug in :class:`TimedeltaIndex` incorrectly allowing indexing with ``Timestamp`` object (:issue:`20464`)
669698
- Fixed bug where subtracting :class:`Timedelta` from an object-dtyped array would raise ``TypeError`` (:issue:`21980`)
670-
-
699+
- 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`)
671700
-
672701

673702
Timezones
@@ -835,4 +864,3 @@ Other
835864
- :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`)
836865
- :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.
837866
- Logical operations ``&, |, ^`` between :class:`Series` and :class:`Index` will no longer raise ``ValueError`` (:issue:`22092`)
838-
-

pandas/core/arrays/interval.py

Lines changed: 1 addition & 6 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def asfreq(self, freq=None, how='E'):
264264
if self.hasnans:
265265
new_data[self._isnan] = iNaT
266266

267-
return self._simple_new(new_data, self.name, freq=freq)
267+
return self._shallow_copy(new_data, freq=freq)
268268

269269
# ------------------------------------------------------------------
270270
# Arithmetic Methods

pandas/core/computation/pytables.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def is_timedelta64_dtype(arr_or_dtype):
467467
return False
468468
try:
469469
tipo = _get_dtype_type(arr_or_dtype)
470-
except:
470+
except (TypeError, ValueError, SyntaxError):
471471
return False
472472
return issubclass(tipo, np.timedelta64)
473473

pandas/core/dtypes/dtypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ def construct_from_string(cls, string):
358358
try:
359359
if string == 'category':
360360
return cls()
361-
except:
361+
else:
362+
raise TypeError("cannot construct a CategoricalDtype")
363+
except AttributeError:
362364
pass
363365

364-
raise TypeError("cannot construct a CategoricalDtype")
365-
366366
@staticmethod
367367
def validate_ordered(ordered):
368368
"""
@@ -519,7 +519,7 @@ def __new__(cls, unit=None, tz=None):
519519
if m is not None:
520520
unit = m.groupdict()['unit']
521521
tz = m.groupdict()['tz']
522-
except:
522+
except TypeError:
523523
raise ValueError("could not construct DatetimeTZDtype")
524524

525525
elif isinstance(unit, compat.string_types):

pandas/core/frame.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@ def _ensure_valid_index(self, value):
32623262
if not len(self.index) and is_list_like(value):
32633263
try:
32643264
value = Series(value)
3265-
except:
3265+
except (ValueError, NotImplementedError, TypeError):
32663266
raise ValueError('Cannot set a frame with no defined index '
32673267
'and a value that cannot be converted to a '
32683268
'Series')
@@ -3631,7 +3631,8 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
36313631
fill_axis=fill_axis,
36323632
broadcast_axis=broadcast_axis)
36333633

3634-
@Appender(_shared_docs['reindex'] % _shared_doc_kwargs)
3634+
@Substitution(**_shared_doc_kwargs)
3635+
@Appender(NDFrame.reindex.__doc__)
36353636
@rewrite_axis_style_signature('labels', [('method', None),
36363637
('copy', True),
36373638
('level', None),
@@ -4500,7 +4501,8 @@ def f(vals):
45004501
# ----------------------------------------------------------------------
45014502
# Sorting
45024503

4503-
@Appender(_shared_docs['sort_values'] % _shared_doc_kwargs)
4504+
@Substitution(**_shared_doc_kwargs)
4505+
@Appender(NDFrame.sort_values.__doc__)
45044506
def sort_values(self, by, axis=0, ascending=True, inplace=False,
45054507
kind='quicksort', na_position='last'):
45064508
inplace = validate_bool_kwarg(inplace, 'inplace')
@@ -4542,7 +4544,8 @@ def sort_values(self, by, axis=0, ascending=True, inplace=False,
45424544
else:
45434545
return self._constructor(new_data).__finalize__(self)
45444546

4545-
@Appender(_shared_docs['sort_index'] % _shared_doc_kwargs)
4547+
@Substitution(**_shared_doc_kwargs)
4548+
@Appender(NDFrame.sort_index.__doc__)
45464549
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
45474550
kind='quicksort', na_position='last', sort_remaining=True,
45484551
by=None):
@@ -4907,7 +4910,7 @@ def _arith_op(left, right):
49074910
left, right = ops.fill_binop(left, right, fill_value)
49084911
return func(left, right)
49094912

4910-
if this._is_mixed_type or other._is_mixed_type:
4913+
if ops.should_series_dispatch(this, other, func):
49114914
# iterate over columns
49124915
return ops.dispatch_to_series(this, other, _arith_op)
49134916
else:
@@ -4917,7 +4920,6 @@ def _arith_op(left, right):
49174920
copy=False)
49184921

49194922
def _combine_match_index(self, other, func, level=None):
4920-
assert isinstance(other, Series)
49214923
left, right = self.align(other, join='outer', axis=0, level=level,
49224924
copy=False)
49234925
assert left.index.equals(right.index)
@@ -4937,11 +4939,7 @@ def _combine_match_columns(self, other, func, level=None, try_cast=True):
49374939
left, right = self.align(other, join='outer', axis=1, level=level,
49384940
copy=False)
49394941
assert left.columns.equals(right.index)
4940-
4941-
new_data = left._data.eval(func=func, other=right,
4942-
axes=[left.columns, self.index],
4943-
try_cast=try_cast)
4944-
return self._constructor(new_data)
4942+
return ops.dispatch_to_series(left, right, func, axis="columns")
49454943

49464944
def _combine_const(self, other, func, errors='raise', try_cast=True):
49474945
if lib.is_scalar(other) or np.ndim(other) == 0:
@@ -7768,7 +7766,7 @@ def convert(v):
77687766
values = np.array([convert(v) for v in values])
77697767
else:
77707768
values = convert(values)
7771-
except:
7769+
except (ValueError, TypeError):
77727770
values = convert(values)
77737771

77747772
else:

0 commit comments

Comments
 (0)