Safer is dtype (#22975) · pandas-dev/pandas@b12e5ba (original) (raw)

6 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -53,18 +53,20 @@ matrix:
53 53 - dist: trusty
54 54 env:
55 55 - 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 +
61 57 - dist: trusty
62 58 env:
63 59 - JOB="3.7, NumPy dev" ENV_FILE="ci/travis-37-numpydev.yaml" TEST_ARGS="--skip-slow --skip-network -W error" PANDAS_TESTING_MODE="deprecate"
64 60 addons:
65 61 apt:
66 62 packages:
67 63 - 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 +
68 70 # In allow_failures
69 71 - dist: trusty
70 72 env:
@@ -73,13 +75,6 @@ matrix:
73 75 - dist: trusty
74 76 env:
75 77 - 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
83 78 - dist: trusty
84 79 env:
85 80 - JOB="3.6, doc" ENV_FILE="ci/travis-36-doc.yaml" DOC=true
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
2 2 import numpy as np
3 3
4 4 from pandas import compat
5 +from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCDataFrame
5 6 from pandas.errors import AbstractMethodError
6 7
7 8
@@ -83,7 +84,12 @@ def is_dtype(cls, dtype):
83 84 """
84 85 dtype = getattr(dtype, 'dtype', dtype)
85 86
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'.
87 93 return False
88 94 elif dtype is None:
89 95 return False
Original file line number Diff line number Diff line change
@@ -4908,7 +4908,8 @@ def _combine_match_index(self, other, func, level=None):
4908 4908 return ops.dispatch_to_series(left, right, func)
4909 4909 else:
4910 4910 # 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
4912 4913 return self._constructor(new_data,
4913 4914 index=left.index, columns=self.columns,
4914 4915 copy=False)
Original file line number Diff line number Diff line change
@@ -4228,7 +4228,7 @@ def _try_cast(arr, take_fast_path):
4228 4228 try:
4229 4229 # gh-15832: Check if we are requesting a numeric dype and
4230 4230 # 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):
4232 4232 subarr = maybe_cast_to_integer_array(arr, dtype)
4233 4233
4234 4234 subarr = maybe_cast_to_datetime(arr, dtype)
Original file line number Diff line number Diff line change
@@ -815,3 +815,23 @@ def test_registry_find(dtype, expected):
815 815 ('datetime64[ns, US/Eastern]', DatetimeTZDtype('ns', 'US/Eastern'))])
816 816 def test_pandas_registry_find(dtype, expected):
817 817 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"])
Original file line number Diff line number Diff line change
@@ -1030,3 +1030,9 @@ def test_alignment_non_pandas(self):
1030 1030 align(df, val, 'index')
1031 1031 with pytest.raises(ValueError):
1032 1032 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)