Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c9d6e89
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Oct 4 08:34:22 2018 -0500

    xpass -> skip

commit 95d5cbf
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Oct 4 08:22:17 2018 -0500

    typo, import

commit 4e9b7f0
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Oct 4 08:18:40 2018 -0500

    doc update

commit cc2bfc8
Merge: 11a0d93 fe67b94
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Oct 4 08:15:46 2018 -0500

    Merge remote-tracking branch 'upstream/master' into ea-divmod

commit fe67b94
Author: Tom Augspurger <TomAugspurger@users.noreply.github.com>
Date:   Thu Oct 4 06:55:09 2018 -0500

    Update type for PeriodDtype / DatetimeTZDtype / IntervalDtype (pandas-dev#22938)

commit b12e5ba
Author: Tom Augspurger <TomAugspurger@users.noreply.github.com>
Date:   Thu Oct 4 06:30:29 2018 -0500

    Safer is dtype (pandas-dev#22975)

commit c19c805
Author: Tom Augspurger <TomAugspurger@users.noreply.github.com>
Date:   Thu Oct 4 06:27:54 2018 -0500

    Catch Exception in combine (pandas-dev#22936)

commit d553ab3
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
Date:   Thu Oct 4 13:24:06 2018 +0200

    TST: Fixturize series/test_combine_concat.py (pandas-dev#22964)

commit 4c78b97
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
Date:   Thu Oct 4 13:23:39 2018 +0200

    TST: Fixturize series/test_constructors.py (pandas-dev#22965)

commit 45d3bb7
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
Date:   Thu Oct 4 13:23:20 2018 +0200

    TST: Fixturize series/test_datetime_values.py (pandas-dev#22966)

commit f1a22ff
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
Date:   Thu Oct 4 13:22:21 2018 +0200

    TST: Fixturize series/test_dtypes.py (pandas-dev#22967)

commit abf68fd
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
Date:   Thu Oct 4 13:21:45 2018 +0200

    TST: Fixturize series/test_io.py (pandas-dev#22972)

commit e6b0c29
Author: Anjali2019 <Anjali2019@users.noreply.github.com>
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 <jorisvandenbossche@gmail.com>
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 <33685575+h-vetinari@users.noreply.github.com>
Date:   Thu Oct 4 03:34:35 2018 +0200

    Fix ASV import error (pandas-dev#22978)

commit 11a0d93
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 14:26:34 2018 -0500

    typerror

commit a0cd5e7
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 14:25:38 2018 -0500

    TypeError for Series

commit 2247461
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 13:29:29 2018 -0500

    Test op(Series[EA], EA])

commit c9fe5d3
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 13:21:33 2018 -0500

    make strict

commit 7ef697c
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 13:14:52 2018 -0500

    Use super

commit 35d4213
Merge: 0671e7d ee80803
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Wed Oct 3 13:11:05 2018 -0500

    Merge remote-tracking branch 'upstream/master' into ea-divmod

commit 0671e7d
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Tue Oct 2 11:10:42 2018 -0500

    Fixup

commit 1b4261f
Merge: c92a4a8 1d9f76c
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Tue Oct 2 10:58:43 2018 -0500

    Merge remote-tracking branch 'upstream/master' into ea-divmod

commit c92a4a8
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Mon Oct 1 16:56:15 2018 -0500

    Update old test

commit 52538fa
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Mon Oct 1 16:51:48 2018 -0500

    BUG: divmod return type
  • Loading branch information
TomAugspurger committed Oct 4, 2018
1 parent 0c7b704 commit d26d3d2
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 168 deletions.
19 changes: 7 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ matrix:
- dist: trusty
env:
- JOB="3.6, coverage" ENV_FILE="ci/travis-36.yaml" TEST_ARGS="--skip-slow --skip-network" PANDAS_TESTING_MODE="deprecate" COVERAGE=true DOCTEST=true
# In allow_failures
- dist: trusty
env:
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true
# In allow_failures

- dist: trusty
env:
- JOB="3.7, NumPy dev" ENV_FILE="ci/travis-37-numpydev.yaml" TEST_ARGS="--skip-slow --skip-network -W error" PANDAS_TESTING_MODE="deprecate"
addons:
apt:
packages:
- xsel

# In allow_failures
- dist: trusty
env:
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true

# In allow_failures
- dist: trusty
env:
Expand All @@ -73,13 +75,6 @@ matrix:
- dist: trusty
env:
- JOB="3.6, slow" ENV_FILE="ci/travis-36-slow.yaml" SLOW=true
- dist: trusty
env:
- JOB="3.7, NumPy dev" ENV_FILE="ci/travis-37-numpydev.yaml" TEST_ARGS="--skip-slow --skip-network -W error" PANDAS_TESTING_MODE="deprecate"
addons:
apt:
packages:
- xsel
- dist: trusty
env:
- JOB="3.6, doc" ENV_FILE="ci/travis-36-doc.yaml" DOC=true
Expand Down
8 changes: 4 additions & 4 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import numpy as np
import pandas.util.testing as tm
from pandas import (Series, DataFrame, MultiIndex, Int64Index, Float64Index,
IntervalIndex, CategoricalIndex,
IndexSlice, concat, date_range)
from .pandas_vb_common import setup, Panel # noqa
from pandas import (Series, DataFrame, MultiIndex, Panel,
Int64Index, Float64Index, IntervalIndex,
CategoricalIndex, IndexSlice, concat, date_range)
from .pandas_vb_common import setup # noqa


class NumericSeriesIndexing(object):
Expand Down
7 changes: 4 additions & 3 deletions asv_bench/benchmarks/join_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

import numpy as np
import pandas.util.testing as tm
from pandas import (DataFrame, Series, MultiIndex, date_range, concat, merge,
merge_asof)
from pandas import (DataFrame, Series, Panel, MultiIndex,
date_range, concat, merge, merge_asof)

try:
from pandas import merge_ordered
except ImportError:
from pandas import ordered_merge as merge_ordered

from .pandas_vb_common import Panel, setup # noqa
from .pandas_vb_common import setup # noqa


class Append(object):
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/panel_ctor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import warnings
from datetime import datetime, timedelta

from pandas import DataFrame, DatetimeIndex, date_range
from pandas import DataFrame, Panel, DatetimeIndex, date_range

from .pandas_vb_common import Panel, setup # noqa
from .pandas_vb_common import setup # noqa


class DifferentIndexes(object):
Expand Down
3 changes: 2 additions & 1 deletion asv_bench/benchmarks/panel_methods.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import warnings

import numpy as np
from pandas import Panel

from .pandas_vb_common import Panel, setup # noqa
from .pandas_vb_common import setup # noqa


class PanelMethods(object):
Expand Down
10 changes: 5 additions & 5 deletions doc/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ your ``MyExtensionArray`` class, as follows:
element one-by-one, this might not be as performant as implementing your own
version of the associated operators directly on the ``ExtensionArray``.

This implementation will try to reconstruct a new ``ExtensionArray`` with the
result of the element-wise operation. Whether or not that succeeds depends on
whether the operation returns a result that's valid for the ``ExtensionArray``.
If an ``ExtensionArray`` cannot be reconstructed, a list containing the scalars
returned instead.
For arithmetic operations, this implementation will try to reconstruct a new
``ExtensionArray`` with the result of the element-wise operation. Whether
or not that succeeds depends on whether the operation returns a result
that's valid for the ``ExtensionArray``. If an ``ExtensionArray`` cannot
be reconstructed, an ndarray containing the scalars returned instead.

.. _extending.extension.testing:

Expand Down
24 changes: 14 additions & 10 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,24 @@ def convert_values(param):
# a TypeError should be raised
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]

if coerce_to_dtype:
if op.__name__ in {'divmod', 'rdivmod'}:
def _maybe_convert(arr):
if coerce_to_dtype:
# https://github.com/pandas-dev/pandas/issues/22850
# We catch all regular exceptions here, and fall back
# to an ndarray.
try:
a, b = zip(*res)
res = (self._from_sequence(a),
self._from_sequence(b))
res = self._from_sequence(arr)
except Exception:
pass
res = np.asarray(arr)
else:
try:
res = self._from_sequence(res)
except Exception:
pass
res = np.asarray(arr)
return res

if op.__name__ in {'divmod', 'rdivmod'}:
a, b = zip(*res)
res = _maybe_convert(a), _maybe_convert(b)
else:
res = _maybe_convert(res)
return res

op_name = ops._get_op_name(op, True)
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np

from pandas import compat
from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCDataFrame
from pandas.errors import AbstractMethodError


Expand Down Expand Up @@ -83,7 +84,12 @@ def is_dtype(cls, dtype):
"""
dtype = getattr(dtype, 'dtype', dtype)

if isinstance(dtype, np.dtype):
if isinstance(dtype, (ABCSeries, ABCIndexClass,
ABCDataFrame, np.dtype)):
# https://github.com/pandas-dev/pandas/issues/22960
# avoid passing data to `construct_from_string`. This could
# cause a FutureWarning from numpy about failing elementwise
# comparison from, e.g., comparing DataFrame == 'category'.
return False
elif dtype is None:
return False
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4908,7 +4908,8 @@ def _combine_match_index(self, other, func, level=None):
return ops.dispatch_to_series(left, right, func)
else:
# fastpath --> operate directly on values
new_data = func(left.values.T, right.values).T
with np.errstate(all="ignore"):
new_data = func(left.values.T, right.values).T
return self._constructor(new_data,
index=left.index, columns=self.columns,
copy=False)
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def _shallow_copy(self, values=None, **kwargs):

return self._simple_new(values, **attributes)

def _shallow_copy_with_infer(self, values=None, **kwargs):
def _shallow_copy_with_infer(self, values, **kwargs):
"""
create a new Index inferring the class with passed value, don't copy
the data, use the same object attributes with passed in attributes
Expand All @@ -553,8 +553,6 @@ def _shallow_copy_with_infer(self, values=None, **kwargs):
values : the values to create the new Index, optional
kwargs : updates the default attributes for this Index
"""
if values is None:
values = self.values
attributes = self._get_attributes_dict()
attributes.update(kwargs)
attributes['copy'] = False
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def view(self, cls=None):
result._id = self._id
return result

def _shallow_copy_with_infer(self, values=None, **kwargs):
def _shallow_copy_with_infer(self, values, **kwargs):
# On equal MultiIndexes the difference is empty.
# Therefore, an empty MultiIndex is returned GH13490
if len(values) == 0:
Expand Down
13 changes: 3 additions & 10 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,10 @@ def _from_ordinals(cls, values, name=None, freq=None, **kwargs):
result = cls._simple_new(data, name=name)
return result

def _shallow_copy(self, values=None, **kwargs):
def _shallow_copy(self, values, **kwargs):
# TODO: simplify, figure out type of values
if values is None:
# Note: this is the Index implementation.
# slightly different from AttributesMixin implementation which
# defaults to self._ndarray_values
values = self.values
else:
# this differs too
if not isinstance(values, PeriodArray):
values = PeriodArray._from_ordinals(values, freq=self.freq)
if not isinstance(values, PeriodArray):
values = PeriodArray._from_ordinals(values, freq=self.freq)

# I don't like overloading shallow_copy with freq changes.
# See if it's used anywhere outside of test_resample_empty_dataframe
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4228,7 +4228,7 @@ def _try_cast(arr, take_fast_path):
try:
# gh-15832: Check if we are requesting a numeric dype and
# that we can convert the data to the requested dtype.
if is_float_dtype(dtype) or is_integer_dtype(dtype):
if is_integer_dtype(dtype):
subarr = maybe_cast_to_integer_array(arr, dtype)

subarr = maybe_cast_to_datetime(arr, dtype)
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,23 @@ def test_registry_find(dtype, expected):
('datetime64[ns, US/Eastern]', DatetimeTZDtype('ns', 'US/Eastern'))])
def test_pandas_registry_find(dtype, expected):
assert _pandas_registry.find(dtype) == expected


@pytest.mark.parametrize("check", [
is_categorical_dtype,
is_datetime64tz_dtype,
is_period_dtype,
is_datetime64_ns_dtype,
is_datetime64_dtype,
is_interval_dtype,
is_datetime64_any_dtype,
is_string_dtype,
is_bool_dtype,
])
def test_is_dtype_no_warning(check):
data = pd.DataFrame({"A": [1, 2]})
with tm.assert_produces_warning(None):
check(data)

with tm.assert_produces_warning(None):
check(data["A"])
2 changes: 1 addition & 1 deletion pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TestInterface(BaseDecimal, base.BaseInterfaceTests):

class TestConstructors(BaseDecimal, base.BaseConstructorsTests):

@pytest.mark.xfail(reason="not implemented constructor from dtype")
@pytest.mark.skip(reason="not implemented constructor from dtype")
def test_from_dtype(self, data):
# construct from our dtype & string dtype
pass
Expand Down
12 changes: 4 additions & 8 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def test_custom_asserts(self):

class TestConstructors(BaseJSON, base.BaseConstructorsTests):

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


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

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

Expand Down Expand Up @@ -204,8 +201,7 @@ def test_combine_add(self, data_repeated):


class TestCasting(BaseJSON, base.BaseCastingTests):
# TODO: Should this be pytest.mark.skip?
@pytest.mark.xfail(reason="failing on np.array(self, dtype=str)")
@pytest.mark.skip(reason="failing on np.array(self, dtype=str)")
def test_astype_str(self):
"""This currently fails in NumPy on np.array(self, dtype=str) with
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def test_take_series(self):
def test_reindex_non_na_fill_value(self):
pass

@pytest.mark.xfail(reason="Categorical.take buggy")
@pytest.mark.skip(reason="Categorical.take buggy")
def test_take_empty(self):
pass

@pytest.mark.xfail(reason="test not written correctly for categorical")
@pytest.mark.skip(reason="test not written correctly for categorical")
def test_reindex(self):
pass

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,3 +1030,9 @@ def test_alignment_non_pandas(self):
align(df, val, 'index')
with pytest.raises(ValueError):
align(df, val, 'columns')

def test_no_warning(self, all_arithmetic_operators):
df = pd.DataFrame({"A": [0., 0.], "B": [0., None]})
b = df['B']
with tm.assert_produces_warning(None):
getattr(df, all_arithmetic_operators)(b, 0)
25 changes: 12 additions & 13 deletions pandas/tests/series/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@
from pandas.util.testing import assert_series_equal
import pandas.util.testing as tm

from .common import TestData

class TestSeriesCombine():

class TestSeriesCombine(TestData):

def test_append(self):
appendedSeries = self.series.append(self.objSeries)
def test_append(self, datetime_series, string_series, object_series):
appendedSeries = string_series.append(object_series)
for idx, value in compat.iteritems(appendedSeries):
if idx in self.series.index:
assert value == self.series[idx]
elif idx in self.objSeries.index:
assert value == self.objSeries[idx]
if idx in string_series.index:
assert value == string_series[idx]
elif idx in object_series.index:
assert value == object_series[idx]
else:
raise AssertionError("orphaned index!")

pytest.raises(ValueError, self.ts.append, self.ts,
pytest.raises(ValueError, datetime_series.append, datetime_series,
verify_integrity=True)

def test_append_many(self):
pieces = [self.ts[:5], self.ts[5:10], self.ts[10:]]
def test_append_many(self, datetime_series):
pieces = [datetime_series[:5], datetime_series[5:10],
datetime_series[10:]]

result = pieces[0].append(pieces[1:])
assert_series_equal(result, self.ts)
assert_series_equal(result, datetime_series)

def test_append_duplicates(self):
# GH 13677
Expand Down
Loading

0 comments on commit d26d3d2

Please sign in to comment.