Skip to content

Commit 6928413

Browse files
committed
Merge remote-tracking branch 'upstream/master' into isort-io
* upstream/master: Make DTI[tz]._values and Series[tz]._values return DTA (pandas-dev#24534) CLN: Refactor some sorting code in Index set operations (pandas-dev#24533) Run isort (pandas-dev#24530) CI: fix db usage in CI (pandas-dev#24529)
2 parents 0ad2f4d + 945445d commit 6928413

Some content is hidden

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

50 files changed

+293
-431
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ matrix:
3434
include:
3535
- dist: trusty
3636
env:
37-
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="not slow and not network"
37+
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="(not slow and not network)"
3838

3939
- dist: trusty
4040
env:
41-
- JOB="2.7" ENV_FILE="ci/deps/travis-27.yaml" PATTERN="not slow and db"
41+
- JOB="2.7" ENV_FILE="ci/deps/travis-27.yaml" PATTERN="(not slow or (single and db))"
4242
addons:
4343
apt:
4444
packages:
4545
- python-gtk2
4646

4747
- dist: trusty
4848
env:
49-
- JOB="3.6, locale" ENV_FILE="ci/deps/travis-36-locale.yaml" PATTERN="not slow and not network and db" LOCALE_OVERRIDE="zh_CN.UTF-8"
49+
- JOB="3.6, locale" ENV_FILE="ci/deps/travis-36-locale.yaml" PATTERN="((not slow and not network) or (single and db))" LOCALE_OVERRIDE="zh_CN.UTF-8"
5050

5151
- dist: trusty
5252
env:
53-
- JOB="3.6, coverage" ENV_FILE="ci/deps/travis-36.yaml" PATTERN="not slow and not network and db" PANDAS_TESTING_MODE="deprecate" COVERAGE=true
53+
- JOB="3.6, coverage" ENV_FILE="ci/deps/travis-36.yaml" PATTERN="((not slow and not network) or (single and db))" PANDAS_TESTING_MODE="deprecate" COVERAGE=true
5454

5555
# In allow_failures
5656
- dist: trusty

pandas/conftest.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import collections
21
from datetime import date, time, timedelta
32
from decimal import Decimal
43
import importlib
@@ -55,24 +54,14 @@ def pytest_runtest_setup(item):
5554
if 'network' in item.keywords and item.config.getoption("--skip-network"):
5655
pytest.skip("skipping due to --skip-network")
5756

57+
if 'db' in item.keywords and item.config.getoption("--skip-db"):
58+
pytest.skip("skipping due to --skip-db")
59+
5860
if 'high_memory' in item.keywords and not item.config.getoption(
5961
"--run-high-memory"):
6062
pytest.skip(
6163
"skipping high memory test since --run-high-memory was not set")
6264

63-
# if "db" not explicitly set in the -m pattern, we skip the db tests
64-
pattern = item.config.getoption('-m')
65-
if 'db' in item.keywords and not pattern:
66-
pytest.skip('skipping db unless -m "db" is specified')
67-
elif 'db' in item.keywords and pattern:
68-
markers = collections.defaultdict(bool)
69-
for marker in item.iter_markers():
70-
markers[marker.name] = True
71-
markers['db'] = False
72-
db_in_pattern = not eval(pattern, {}, markers)
73-
if not db_in_pattern:
74-
pytest.skip('skipping db unless -m "db" is specified')
75-
7665

7766
# Configurations for all tests and all test modules
7867

pandas/core/dtypes/concat.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ def _concat_datetime(to_concat, axis=0, typs=None):
426426
if any(typ.startswith('datetime') for typ in typs):
427427

428428
if 'datetime' in typs:
429-
to_concat = [np.array(x, copy=False).view(np.int64)
430-
for x in to_concat]
429+
to_concat = [x.astype(np.int64, copy=False) for x in to_concat]
431430
return _concatenate_2d(to_concat, axis=axis).view(_NS_DTYPE)
432431
else:
433432
# when to_concat has different tz, len(typs) > 1.
@@ -451,7 +450,7 @@ def _convert_datetimelike_to_object(x):
451450
# if dtype is of datetimetz or timezone
452451
if x.dtype.kind == _NS_DTYPE.kind:
453452
if getattr(x, 'tz', None) is not None:
454-
x = x.astype(object).values
453+
x = np.asarray(x.astype(object))
455454
else:
456455
shape = x.shape
457456
x = tslib.ints_to_pydatetime(x.view(np.int64).ravel(),

pandas/core/indexes/base.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -2302,27 +2302,15 @@ def union(self, other):
23022302
allow_fill=False)
23032303
result = _concat._concat_compat((lvals, other_diff))
23042304

2305-
try:
2306-
lvals[0] < other_diff[0]
2307-
except TypeError as e:
2308-
warnings.warn("%s, sort order is undefined for "
2309-
"incomparable objects" % e, RuntimeWarning,
2310-
stacklevel=3)
2311-
else:
2312-
types = frozenset((self.inferred_type,
2313-
other.inferred_type))
2314-
if not types & _unsortable_types:
2315-
result.sort()
2316-
23172305
else:
23182306
result = lvals
23192307

2320-
try:
2321-
result = np.sort(result)
2322-
except TypeError as e:
2323-
warnings.warn("%s, sort order is undefined for "
2324-
"incomparable objects" % e, RuntimeWarning,
2325-
stacklevel=3)
2308+
try:
2309+
result = sorting.safe_sort(result)
2310+
except TypeError as e:
2311+
warnings.warn("%s, sort order is undefined for "
2312+
"incomparable objects" % e, RuntimeWarning,
2313+
stacklevel=3)
23262314

23272315
# for subclasses
23282316
return self._wrap_setop_result(other, result)

pandas/core/indexes/datetimes.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None):
316316
we require the we have a dtype compat for the values
317317
if we are passed a non-dtype compat, then coerce using the constructor
318318
"""
319+
if isinstance(values, DatetimeArray):
320+
values = DatetimeArray(values, freq=freq, tz=tz, dtype=dtype)
321+
tz = values.tz
322+
freq = values.freq
323+
values = values._data
324+
319325
# DatetimeArray._simple_new will accept either i8 or M8[ns] dtypes
320326
assert isinstance(values, np.ndarray), type(values)
321327

@@ -340,7 +346,7 @@ def _values(self):
340346
# tz-naive -> ndarray
341347
# tz-aware -> DatetimeIndex
342348
if self.tz is not None:
343-
return self
349+
return self._eadata
344350
else:
345351
return self.values
346352

@@ -629,6 +635,9 @@ def intersection(self, other):
629635
not other.freq.isAnchored() or
630636
(not self.is_monotonic or not other.is_monotonic)):
631637
result = Index.intersection(self, other)
638+
# Invalidate the freq of `result`, which may not be correct at
639+
# this point, depending on the values.
640+
result.freq = None
632641
result = self._shallow_copy(result._values, name=result.name,
633642
tz=result.tz, freq=None)
634643
if result.freq is None:

pandas/core/internals/blocks.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
_isna_compat, array_equivalent, is_null_datelike_scalar, isna, notna)
3535

3636
import pandas.core.algorithms as algos
37-
from pandas.core.arrays import Categorical, ExtensionArray
37+
from pandas.core.arrays import (
38+
Categorical, DatetimeArrayMixin as DatetimeArray, ExtensionArray)
3839
from pandas.core.base import PandasObject
3940
import pandas.core.common as com
4041
from pandas.core.indexes.datetimes import DatetimeIndex
@@ -2437,8 +2438,14 @@ def _try_coerce_args(self, values, other):
24372438
""" provide coercion to our input arguments """
24382439

24392440
if isinstance(other, ABCDatetimeIndex):
2440-
# to store DatetimeTZBlock as object
2441-
other = other.astype(object).values
2441+
# May get a DatetimeIndex here. Unbox it.
2442+
other = other.array
2443+
2444+
if isinstance(other, DatetimeArray):
2445+
# hit in pandas/tests/indexing/test_coercion.py
2446+
# ::TestWhereCoercion::test_where_series_datetime64[datetime64tz]
2447+
# when falling back to ObjectBlock.where
2448+
other = other.astype(object)
24422449

24432450
return values, other
24442451

@@ -2985,7 +2992,8 @@ def _try_coerce_args(self, values, other):
29852992
elif (is_null_datelike_scalar(other) or
29862993
(lib.is_scalar(other) and isna(other))):
29872994
other = tslibs.iNaT
2988-
elif isinstance(other, self._holder):
2995+
elif isinstance(other, (self._holder, DatetimeArray)):
2996+
# TODO: DatetimeArray check will be redundant after GH#24024
29892997
if other.tz != self.values.tz:
29902998
raise ValueError("incompatible or non tz-aware value")
29912999
other = _block_shape(other.asi8, ndim=self.ndim)

pandas/core/series.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ def _values(self):
477477
"""
478478
Return the internal repr of this data.
479479
"""
480-
return self._data.internal_values()
480+
result = self._data.internal_values()
481+
if isinstance(result, DatetimeIndex):
482+
result = result._eadata
483+
return result
481484

482485
def _formatting_values(self):
483486
"""
@@ -1602,10 +1605,6 @@ def unique(self):
16021605
Categories (3, object): [a < b < c]
16031606
"""
16041607
result = super(Series, self).unique()
1605-
if isinstance(result, DatetimeIndex):
1606-
# TODO: This should be unnecessary after Series._values returns
1607-
# DatetimeArray
1608-
result = result._eadata
16091608
return result
16101609

16111610
def drop_duplicates(self, keep='first', inplace=False):

pandas/tests/frame/common.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import numpy as np
22

3-
from pandas import compat
43
from pandas.util._decorators import cache_readonly
5-
import pandas.util.testing as tm
4+
65
import pandas as pd
6+
from pandas import compat
7+
import pandas.util.testing as tm
78

89
_seriesd = tm.getSeriesData()
910
_tsd = tm.getTimeSeriesData()

pandas/tests/frame/conftest.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import pytest
2-
31
import numpy as np
2+
import pytest
43

5-
from pandas import compat
4+
from pandas import DataFrame, NaT, compat, date_range
65
import pandas.util.testing as tm
7-
from pandas import DataFrame, date_range, NaT
86

97

108
@pytest.fixture

pandas/tests/frame/test_alter_axes.py

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

33
from __future__ import print_function
44

5-
import inspect
6-
import pytest
7-
85
from datetime import datetime, timedelta
6+
import inspect
97

108
import numpy as np
9+
import pytest
10+
11+
from pandas.compat import PY2, lrange
1112

12-
from pandas.compat import lrange, PY2
13-
from pandas import (DataFrame, Series, Index, MultiIndex, RangeIndex,
14-
IntervalIndex, DatetimeIndex, Categorical, cut,
15-
Timestamp, date_range, to_datetime)
1613
from pandas.core.dtypes.common import (
17-
is_object_dtype,
18-
is_categorical_dtype,
19-
is_interval_dtype)
14+
is_categorical_dtype, is_interval_dtype, is_object_dtype)
2015

16+
from pandas import (
17+
Categorical, DataFrame, DatetimeIndex, Index, IntervalIndex, MultiIndex,
18+
RangeIndex, Series, Timestamp, cut, date_range, to_datetime)
2119
import pandas.util.testing as tm
2220

2321

pandas/tests/frame/test_analytics.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
from __future__ import print_function
44

5-
import warnings
65
from datetime import timedelta
76
import operator
8-
import pytest
9-
107
from string import ascii_lowercase
8+
import warnings
9+
10+
import numpy as np
1111
from numpy import nan
1212
from numpy.random import randn
13-
import numpy as np
13+
import pytest
14+
15+
from pandas.compat import PY35, lrange
16+
import pandas.util._test_decorators as td
1417

15-
from pandas.compat import lrange, PY35
16-
from pandas import (compat, isna, notna, DataFrame, Series,
17-
MultiIndex, date_range, Timestamp, Categorical,
18-
to_datetime, to_timedelta)
1918
import pandas as pd
20-
import pandas.core.nanops as nanops
19+
from pandas import (
20+
Categorical, DataFrame, MultiIndex, Series, Timestamp, compat, date_range,
21+
isna, notna, to_datetime, to_timedelta)
2122
import pandas.core.algorithms as algorithms
22-
23+
import pandas.core.nanops as nanops
2324
import pandas.util.testing as tm
24-
import pandas.util._test_decorators as td
2525

2626

2727
def assert_stat_op_calc(opname, alternative, frame, has_skipna=True,

pandas/tests/frame/test_api.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@
22

33
from __future__ import print_function
44

5-
import pytest
6-
75
# pylint: disable-msg=W0612,E1101
86
from copy import deepcopy
97
import pydoc
108

11-
from pandas.compat import range, lrange, long
12-
from pandas import compat
13-
14-
from numpy.random import randn
159
import numpy as np
10+
from numpy.random import randn
11+
import pytest
1612

17-
from pandas import (DataFrame, Series, date_range, timedelta_range,
18-
Categorical, SparseDataFrame)
19-
import pandas as pd
20-
21-
from pandas.util.testing import (assert_almost_equal,
22-
assert_series_equal,
23-
assert_frame_equal)
13+
from pandas.compat import long, lrange, range
2414

15+
import pandas as pd
16+
from pandas import (
17+
Categorical, DataFrame, Series, SparseDataFrame, compat, date_range,
18+
timedelta_range)
2519
import pandas.util.testing as tm
20+
from pandas.util.testing import (
21+
assert_almost_equal, assert_frame_equal, assert_series_equal)
2622

2723

2824
class SharedWithSparse(object):

pandas/tests/frame/test_apply.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
from __future__ import print_function
44

5-
import pytest
6-
7-
import operator
85
from collections import OrderedDict
96
from datetime import datetime
107
from itertools import chain
11-
8+
import operator
129
import warnings
10+
1311
import numpy as np
12+
import pytest
1413

15-
from pandas import (notna, DataFrame, Series, MultiIndex, date_range,
16-
Timestamp, compat)
17-
import pandas as pd
1814
from pandas.core.dtypes.dtypes import CategoricalDtype
15+
16+
import pandas as pd
17+
from pandas import (
18+
DataFrame, MultiIndex, Series, Timestamp, compat, date_range, notna)
19+
from pandas.conftest import _get_cython_table_params
1920
from pandas.core.apply import frame_apply
20-
from pandas.util.testing import (assert_series_equal,
21-
assert_frame_equal)
2221
import pandas.util.testing as tm
23-
from pandas.conftest import _get_cython_table_params
22+
from pandas.util.testing import assert_frame_equal, assert_series_equal
2423

2524

2625
@pytest.fixture

pandas/tests/frame/test_arithmetic.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
from datetime import datetime
44
import operator
55

6-
import pytest
76
import numpy as np
7+
import pytest
88

99
from pandas.compat import range
1010

1111
import pandas as pd
12-
import pandas.util.testing as tm
13-
1412
from pandas.tests.frame.common import _check_mixed_float, _check_mixed_int
15-
13+
import pandas.util.testing as tm
1614

1715
# -------------------------------------------------------------------
1816
# Comparisons
1917

18+
2019
class TestFrameComparisons(object):
2120
# Specifically _not_ flex-comparisons
2221

0 commit comments

Comments
 (0)