Skip to content

Commit d26d3d2

Browse files
committed
Squashed commit of the following:
commit c9d6e89 Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 08:34:22 2018 -0500 xpass -> skip commit 95d5cbf Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 08:22:17 2018 -0500 typo, import commit 4e9b7f0 Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 08:18:40 2018 -0500 doc update commit cc2bfc8 Merge: 11a0d93 fe67b94 Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 08:15:46 2018 -0500 Merge remote-tracking branch 'upstream/master' into ea-divmod commit fe67b94 Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 06:55:09 2018 -0500 Update type for PeriodDtype / DatetimeTZDtype / IntervalDtype (pandas-dev#22938) commit b12e5ba Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 06:30:29 2018 -0500 Safer is dtype (pandas-dev#22975) commit c19c805 Author: Tom Augspurger <[email protected]> Date: Thu Oct 4 06:27:54 2018 -0500 Catch Exception in combine (pandas-dev#22936) commit d553ab3 Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:24:06 2018 +0200 TST: Fixturize series/test_combine_concat.py (pandas-dev#22964) commit 4c78b97 Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:23:39 2018 +0200 TST: Fixturize series/test_constructors.py (pandas-dev#22965) commit 45d3bb7 Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:23:20 2018 +0200 TST: Fixturize series/test_datetime_values.py (pandas-dev#22966) commit f1a22ff Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:22:21 2018 +0200 TST: Fixturize series/test_dtypes.py (pandas-dev#22967) commit abf68fd Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:21:45 2018 +0200 TST: Fixturize series/test_io.py (pandas-dev#22972) commit e6b0c29 Author: Anjali2019 <[email protected]> Date: Thu Oct 4 13:20:46 2018 +0200 TST: Fixturize series/test_missing.py (pandas-dev#22973) commit 9b405b8 Author: Joris Van den Bossche <[email protected]> Date: Thu Oct 4 13:16:28 2018 +0200 CLN: values is required argument in _shallow_copy_with_infer (pandas-dev#22983) commit c282e31 Author: h-vetinari <[email protected]> Date: Thu Oct 4 03:34:35 2018 +0200 Fix ASV import error (pandas-dev#22978) 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 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 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
1 parent 0c7b704 commit d26d3d2

24 files changed

+182
-168
lines changed

.travis.yml

+7-12
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@ matrix:
5353
- dist: trusty
5454
env:
5555
- JOB="3.6, coverage" ENV_FILE="ci/travis-36.yaml" TEST_ARGS="--skip-slow --skip-network" PANDAS_TESTING_MODE="deprecate" COVERAGE=true DOCTEST=true
56-
# In allow_failures
57-
- dist: trusty
58-
env:
59-
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true
60-
# In allow_failures
56+
6157
- dist: trusty
6258
env:
6359
- JOB="3.7, NumPy dev" ENV_FILE="ci/travis-37-numpydev.yaml" TEST_ARGS="--skip-slow --skip-network -W error" PANDAS_TESTING_MODE="deprecate"
6460
addons:
6561
apt:
6662
packages:
6763
- xsel
64+
65+
# In allow_failures
66+
- dist: trusty
67+
env:
68+
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true
69+
6870
# In allow_failures
6971
- dist: trusty
7072
env:
@@ -73,13 +75,6 @@ matrix:
7375
- dist: trusty
7476
env:
7577
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true
76-
- dist: trusty
77-
env:
78-
- JOB="3.7, NumPy dev" ENV_FILE="ci/travis-37-numpydev.yaml" TEST_ARGS="--skip-slow --skip-network -W error" PANDAS_TESTING_MODE="deprecate"
79-
addons:
80-
apt:
81-
packages:
82-
- xsel
8378
- dist: trusty
8479
env:
8580
- JOB="3.6, doc" ENV_FILE="ci/travis-36-doc.yaml" DOC=true

asv_bench/benchmarks/indexing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import numpy as np
44
import pandas.util.testing as tm
5-
from pandas import (Series, DataFrame, MultiIndex, Int64Index, Float64Index,
6-
IntervalIndex, CategoricalIndex,
7-
IndexSlice, concat, date_range)
8-
from .pandas_vb_common import setup, Panel # noqa
5+
from pandas import (Series, DataFrame, MultiIndex, Panel,
6+
Int64Index, Float64Index, IntervalIndex,
7+
CategoricalIndex, IndexSlice, concat, date_range)
8+
from .pandas_vb_common import setup # noqa
99

1010

1111
class NumericSeriesIndexing(object):

asv_bench/benchmarks/join_merge.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
import numpy as np
55
import pandas.util.testing as tm
6-
from pandas import (DataFrame, Series, MultiIndex, date_range, concat, merge,
7-
merge_asof)
6+
from pandas import (DataFrame, Series, Panel, MultiIndex,
7+
date_range, concat, merge, merge_asof)
8+
89
try:
910
from pandas import merge_ordered
1011
except ImportError:
1112
from pandas import ordered_merge as merge_ordered
1213

13-
from .pandas_vb_common import Panel, setup # noqa
14+
from .pandas_vb_common import setup # noqa
1415

1516

1617
class Append(object):

asv_bench/benchmarks/panel_ctor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import warnings
22
from datetime import datetime, timedelta
33

4-
from pandas import DataFrame, DatetimeIndex, date_range
4+
from pandas import DataFrame, Panel, DatetimeIndex, date_range
55

6-
from .pandas_vb_common import Panel, setup # noqa
6+
from .pandas_vb_common import setup # noqa
77

88

99
class DifferentIndexes(object):

asv_bench/benchmarks/panel_methods.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import warnings
22

33
import numpy as np
4+
from pandas import Panel
45

5-
from .pandas_vb_common import Panel, setup # noqa
6+
from .pandas_vb_common import setup # noqa
67

78

89
class PanelMethods(object):

doc/source/extending.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ your ``MyExtensionArray`` class, as follows:
167167
element one-by-one, this might not be as performant as implementing your own
168168
version of the associated operators directly on the ``ExtensionArray``.
169169

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.
170+
For arithmetic operations, this implementation will try to reconstruct a new
171+
``ExtensionArray`` with the result of the element-wise operation. Whether
172+
or not that succeeds depends on whether the operation returns a result
173+
that's valid for the ``ExtensionArray``. If an ``ExtensionArray`` cannot
174+
be reconstructed, an ndarray containing the scalars returned instead.
175175

176176
.. _extending.extension.testing:
177177

pandas/core/arrays/base.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -781,20 +781,24 @@ def convert_values(param):
781781
# a TypeError should be raised
782782
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
783783

784-
if coerce_to_dtype:
785-
if op.__name__ in {'divmod', 'rdivmod'}:
784+
def _maybe_convert(arr):
785+
if coerce_to_dtype:
786+
# https://github.com/pandas-dev/pandas/issues/22850
787+
# We catch all regular exceptions here, and fall back
788+
# to an ndarray.
786789
try:
787-
a, b = zip(*res)
788-
res = (self._from_sequence(a),
789-
self._from_sequence(b))
790+
res = self._from_sequence(arr)
790791
except Exception:
791-
pass
792+
res = np.asarray(arr)
792793
else:
793-
try:
794-
res = self._from_sequence(res)
795-
except Exception:
796-
pass
794+
res = np.asarray(arr)
795+
return res
797796

797+
if op.__name__ in {'divmod', 'rdivmod'}:
798+
a, b = zip(*res)
799+
res = _maybe_convert(a), _maybe_convert(b)
800+
else:
801+
res = _maybe_convert(res)
798802
return res
799803

800804
op_name = ops._get_op_name(op, True)

pandas/core/dtypes/base.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33

44
from pandas import compat
5+
from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCDataFrame
56
from pandas.errors import AbstractMethodError
67

78

@@ -83,7 +84,12 @@ def is_dtype(cls, dtype):
8384
"""
8485
dtype = getattr(dtype, 'dtype', dtype)
8586

86-
if isinstance(dtype, np.dtype):
87+
if isinstance(dtype, (ABCSeries, ABCIndexClass,
88+
ABCDataFrame, np.dtype)):
89+
# https://github.com/pandas-dev/pandas/issues/22960
90+
# avoid passing data to `construct_from_string`. This could
91+
# cause a FutureWarning from numpy about failing elementwise
92+
# comparison from, e.g., comparing DataFrame == 'category'.
8793
return False
8894
elif dtype is None:
8995
return False

pandas/core/frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4908,7 +4908,8 @@ def _combine_match_index(self, other, func, level=None):
49084908
return ops.dispatch_to_series(left, right, func)
49094909
else:
49104910
# fastpath --> operate directly on values
4911-
new_data = func(left.values.T, right.values).T
4911+
with np.errstate(all="ignore"):
4912+
new_data = func(left.values.T, right.values).T
49124913
return self._constructor(new_data,
49134914
index=left.index, columns=self.columns,
49144915
copy=False)

pandas/core/indexes/base.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _shallow_copy(self, values=None, **kwargs):
540540

541541
return self._simple_new(values, **attributes)
542542

543-
def _shallow_copy_with_infer(self, values=None, **kwargs):
543+
def _shallow_copy_with_infer(self, values, **kwargs):
544544
"""
545545
create a new Index inferring the class with passed value, don't copy
546546
the data, use the same object attributes with passed in attributes
@@ -553,8 +553,6 @@ def _shallow_copy_with_infer(self, values=None, **kwargs):
553553
values : the values to create the new Index, optional
554554
kwargs : updates the default attributes for this Index
555555
"""
556-
if values is None:
557-
values = self.values
558556
attributes = self._get_attributes_dict()
559557
attributes.update(kwargs)
560558
attributes['copy'] = False

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def view(self, cls=None):
556556
result._id = self._id
557557
return result
558558

559-
def _shallow_copy_with_infer(self, values=None, **kwargs):
559+
def _shallow_copy_with_infer(self, values, **kwargs):
560560
# On equal MultiIndexes the difference is empty.
561561
# Therefore, an empty MultiIndex is returned GH13490
562562
if len(values) == 0:

pandas/core/indexes/period.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,10 @@ def _from_ordinals(cls, values, name=None, freq=None, **kwargs):
252252
result = cls._simple_new(data, name=name)
253253
return result
254254

255-
def _shallow_copy(self, values=None, **kwargs):
255+
def _shallow_copy(self, values, **kwargs):
256256
# TODO: simplify, figure out type of values
257-
if values is None:
258-
# Note: this is the Index implementation.
259-
# slightly different from AttributesMixin implementation which
260-
# defaults to self._ndarray_values
261-
values = self.values
262-
else:
263-
# this differs too
264-
if not isinstance(values, PeriodArray):
265-
values = PeriodArray._from_ordinals(values, freq=self.freq)
257+
if not isinstance(values, PeriodArray):
258+
values = PeriodArray._from_ordinals(values, freq=self.freq)
266259

267260
# I don't like overloading shallow_copy with freq changes.
268261
# See if it's used anywhere outside of test_resample_empty_dataframe

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,7 @@ def _try_cast(arr, take_fast_path):
42284228
try:
42294229
# gh-15832: Check if we are requesting a numeric dype and
42304230
# that we can convert the data to the requested dtype.
4231-
if is_float_dtype(dtype) or is_integer_dtype(dtype):
4231+
if is_integer_dtype(dtype):
42324232
subarr = maybe_cast_to_integer_array(arr, dtype)
42334233

42344234
subarr = maybe_cast_to_datetime(arr, dtype)

pandas/tests/dtypes/test_dtypes.py

+20
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,23 @@ def test_registry_find(dtype, expected):
815815
('datetime64[ns, US/Eastern]', DatetimeTZDtype('ns', 'US/Eastern'))])
816816
def test_pandas_registry_find(dtype, expected):
817817
assert _pandas_registry.find(dtype) == expected
818+
819+
820+
@pytest.mark.parametrize("check", [
821+
is_categorical_dtype,
822+
is_datetime64tz_dtype,
823+
is_period_dtype,
824+
is_datetime64_ns_dtype,
825+
is_datetime64_dtype,
826+
is_interval_dtype,
827+
is_datetime64_any_dtype,
828+
is_string_dtype,
829+
is_bool_dtype,
830+
])
831+
def test_is_dtype_no_warning(check):
832+
data = pd.DataFrame({"A": [1, 2]})
833+
with tm.assert_produces_warning(None):
834+
check(data)
835+
836+
with tm.assert_produces_warning(None):
837+
check(data["A"])

pandas/tests/extension/decimal/test_decimal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class TestInterface(BaseDecimal, base.BaseInterfaceTests):
102102

103103
class TestConstructors(BaseDecimal, base.BaseConstructorsTests):
104104

105-
@pytest.mark.xfail(reason="not implemented constructor from dtype")
105+
@pytest.mark.skip(reason="not implemented constructor from dtype")
106106
def test_from_dtype(self, data):
107107
# construct from our dtype & string dtype
108108
pass

pandas/tests/extension/json/test_json.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ def test_custom_asserts(self):
131131

132132
class TestConstructors(BaseJSON, base.BaseConstructorsTests):
133133

134-
# TODO: Should this be pytest.mark.skip?
135-
@pytest.mark.xfail(reason="not implemented constructor from dtype")
134+
@pytest.mark.skip(reason="not implemented constructor from dtype")
136135
def test_from_dtype(self, data):
137136
# construct from our dtype & string dtype
138137
pass
@@ -147,13 +146,11 @@ class TestGetitem(BaseJSON, base.BaseGetitemTests):
147146

148147

149148
class TestMissing(BaseJSON, base.BaseMissingTests):
150-
# TODO: Should this be pytest.mark.skip?
151-
@pytest.mark.xfail(reason="Setting a dict as a scalar")
149+
@pytest.mark.skip(reason="Setting a dict as a scalar")
152150
def test_fillna_series(self):
153151
"""We treat dictionaries as a mapping in fillna, not a scalar."""
154152

155-
# TODO: Should this be pytest.mark.skip?
156-
@pytest.mark.xfail(reason="Setting a dict as a scalar")
153+
@pytest.mark.skip(reason="Setting a dict as a scalar")
157154
def test_fillna_frame(self):
158155
"""We treat dictionaries as a mapping in fillna, not a scalar."""
159156

@@ -204,8 +201,7 @@ def test_combine_add(self, data_repeated):
204201

205202

206203
class TestCasting(BaseJSON, base.BaseCastingTests):
207-
# TODO: Should this be pytest.mark.skip?
208-
@pytest.mark.xfail(reason="failing on np.array(self, dtype=str)")
204+
@pytest.mark.skip(reason="failing on np.array(self, dtype=str)")
209205
def test_astype_str(self):
210206
"""This currently fails in NumPy on np.array(self, dtype=str) with
211207

pandas/tests/extension/test_categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def test_take_series(self):
140140
def test_reindex_non_na_fill_value(self):
141141
pass
142142

143-
@pytest.mark.xfail(reason="Categorical.take buggy")
143+
@pytest.mark.skip(reason="Categorical.take buggy")
144144
def test_take_empty(self):
145145
pass
146146

147-
@pytest.mark.xfail(reason="test not written correctly for categorical")
147+
@pytest.mark.skip(reason="test not written correctly for categorical")
148148
def test_reindex(self):
149149
pass
150150

pandas/tests/frame/test_operators.py

+6
Original file line numberDiff line numberDiff line change
@@ -1030,3 +1030,9 @@ def test_alignment_non_pandas(self):
10301030
align(df, val, 'index')
10311031
with pytest.raises(ValueError):
10321032
align(df, val, 'columns')
1033+
1034+
def test_no_warning(self, all_arithmetic_operators):
1035+
df = pd.DataFrame({"A": [0., 0.], "B": [0., None]})
1036+
b = df['B']
1037+
with tm.assert_produces_warning(None):
1038+
getattr(df, all_arithmetic_operators)(b, 0)

pandas/tests/series/test_combine_concat.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,28 @@
1515
from pandas.util.testing import assert_series_equal
1616
import pandas.util.testing as tm
1717

18-
from .common import TestData
1918

19+
class TestSeriesCombine():
2020

21-
class TestSeriesCombine(TestData):
22-
23-
def test_append(self):
24-
appendedSeries = self.series.append(self.objSeries)
21+
def test_append(self, datetime_series, string_series, object_series):
22+
appendedSeries = string_series.append(object_series)
2523
for idx, value in compat.iteritems(appendedSeries):
26-
if idx in self.series.index:
27-
assert value == self.series[idx]
28-
elif idx in self.objSeries.index:
29-
assert value == self.objSeries[idx]
24+
if idx in string_series.index:
25+
assert value == string_series[idx]
26+
elif idx in object_series.index:
27+
assert value == object_series[idx]
3028
else:
3129
raise AssertionError("orphaned index!")
3230

33-
pytest.raises(ValueError, self.ts.append, self.ts,
31+
pytest.raises(ValueError, datetime_series.append, datetime_series,
3432
verify_integrity=True)
3533

36-
def test_append_many(self):
37-
pieces = [self.ts[:5], self.ts[5:10], self.ts[10:]]
34+
def test_append_many(self, datetime_series):
35+
pieces = [datetime_series[:5], datetime_series[5:10],
36+
datetime_series[10:]]
3837

3938
result = pieces[0].append(pieces[1:])
40-
assert_series_equal(result, self.ts)
39+
assert_series_equal(result, datetime_series)
4140

4241
def test_append_duplicates(self):
4342
# GH 13677

0 commit comments

Comments
 (0)