From d18128083aea689ae9a2effbf9b6803820ae9e76 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 18 Dec 2019 17:01:13 -0800 Subject: [PATCH 01/11] CLN: assorted --- doc/source/whatsnew/v1.0.0.rst | 4 ++-- pandas/tests/extension/test_numpy.py | 8 ++++---- pandas/tests/io/excel/test_readers.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index c072bfeff4a72..37952768344d3 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -578,8 +578,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - :meth:`Series.where` with ``Categorical`` dtype (or :meth:`DataFrame.where` with ``Categorical`` column) no longer allows setting new categories (:issue:`24114`) - :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` constructors no longer allow ``start``, ``end``, and ``periods`` keywords, use :func:`date_range`, :func:`timedelta_range`, and :func:`period_range` instead (:issue:`23919`) - :class:`DatetimeIndex` and :class:`TimedeltaIndex` constructors no longer have a ``verify_integrity`` keyword argument (:issue:`23919`) -- ``pandas.core.internals.blocks.make_block`` no longer accepts the "fastpath" keyword(:issue:`19265`) -- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword(:issue:`19434`) +- ``pandas.core.internals.blocks.make_block`` no longer accepts the "fastpath" keyword (:issue:`19265`) +- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword (:issue:`19434`) - Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`) - Removed the previously deprecated :meth:`MultiIndex.to_hierarchical` (:issue:`21613`) - Removed the previously deprecated :attr:`MultiIndex.labels`, use :attr:`MultiIndex.codes` instead (:issue:`23752`) diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index 221cf0787d839..1d6b53b754ac9 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -51,7 +51,7 @@ def data_missing(allow_in_pandas, dtype): if dtype.numpy_dtype == "object": if _np_version_under1p16: raise pytest.skip("Skipping for NumPy <1.16") - return PandasArray(np.array([np.nan, (1,)])) + return PandasArray(np.array([np.nan, (1,)], dtype=object)) return PandasArray(np.array([np.nan, 1.0])) @@ -78,7 +78,7 @@ def data_for_sorting(allow_in_pandas, dtype): if dtype.numpy_dtype == "object": # Use an empty tuple for first element, then remove, # to disable np.array's shape inference. - return PandasArray(np.array([(), (2,), (3,), (1,)])[1:]) + return PandasArray(np.array([(), (2,), (3,), (1,)], dtype=object)[1:]) return PandasArray(np.array([1, 2, 0])) @@ -90,7 +90,7 @@ def data_missing_for_sorting(allow_in_pandas, dtype): A < B and NA missing. """ if dtype.numpy_dtype == "object": - return PandasArray(np.array([(1,), np.nan, (0,)])) + return PandasArray(np.array([(1,), np.nan, (0,)], dtype=object)) return PandasArray(np.array([1, np.nan, 0])) @@ -106,7 +106,7 @@ def data_for_grouping(allow_in_pandas, dtype): a, b, c = (1,), (2,), (3,) else: a, b, c = np.arange(3) - return PandasArray(np.array([b, b, np.nan, np.nan, a, a, b, c])) + return PandasArray(np.array([b, b, np.nan, np.nan, a, a, b, c], dtype=dtype.numpy_dtype)) @pytest.fixture diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 480407664285f..73f2ee004f50a 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -77,7 +77,7 @@ def cd_and_set_engine(self, engine, datapath, monkeypatch, read_ext): pytest.skip() if engine == "odf" and read_ext != ".ods": pytest.skip() - if read_ext == ".ods" and engine != "odf": + if engine != "odf" and read_ext == ".ods": pytest.skip() func = partial(pd.read_excel, engine=engine) @@ -810,11 +810,11 @@ def cd_and_set_engine(self, engine, datapath, monkeypatch, read_ext): """ Change directory and set engine for ExcelFile objects. """ - if engine == "odf" and read_ext != ".ods": + if engine == "openpyxl" and read_ext == ".xls": pytest.skip() - if read_ext == ".ods" and engine != "odf": + if engine == "odf" and read_ext != ".ods": pytest.skip() - if engine == "openpyxl" and read_ext == ".xls": + if engine != "odf" and read_ext == ".ods": pytest.skip() func = partial(pd.ExcelFile, engine=engine) From 7bf6b6f95c9e252bb6a758605d0eaac2ce3cd4a3 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 20 Dec 2019 08:29:45 -0800 Subject: [PATCH 02/11] CLN old comment --- pandas/io/parsers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index a887a537a2201..3c4bc63247b47 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -2229,8 +2229,6 @@ class PythonParser(ParserBase): def __init__(self, f, **kwds): """ Workhorse function for processing nested list into DataFrame - - Should be replaced by np.genfromtxt eventually? """ ParserBase.__init__(self, kwds) From 5a4cd674ffc141d8e8142573c5e0f3573d54d72e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 20 Dec 2019 08:30:45 -0800 Subject: [PATCH 03/11] request from #30336 --- pandas/core/arrays/datetimes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 10669b09cefec..1d4052ad8b114 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -802,8 +802,8 @@ def _add_offset(self, offset): PerformanceWarning, ) result = self.astype("O") + offset - if len(self) == 0: - # _from_sequence won't be able to infer self.tz + if not len(self): + # GH#30336 _from_sequence won't be able to infer self.tz return type(self)._from_sequence(result).tz_localize(self.tz) return type(self)._from_sequence(result, freq="infer") From f6f96789e830501f69a9e1a9993f5b9897a479b6 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 21 Dec 2019 12:56:23 -0800 Subject: [PATCH 04/11] cleanup --- pandas/_libs/reshape.pyx | 2 +- pandas/core/internals/managers.py | 6 ++++-- pandas/plotting/_matplotlib/core.py | 6 ------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/_libs/reshape.pyx b/pandas/_libs/reshape.pyx index 32aa936672aab..4e831081c8e54 100644 --- a/pandas/_libs/reshape.pyx +++ b/pandas/_libs/reshape.pyx @@ -28,7 +28,7 @@ def unstack(reshape_t[:, :] values, uint8_t[:] mask, Py_ssize_t stride, Py_ssize_t length, Py_ssize_t width, reshape_t[:, :] new_values, uint8_t[:, :] new_mask): """ - transform long sorted_values to wide new_values + Transform long values to wide new_values. Parameters ---------- diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index a81209229a3b8..d15a95191745b 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -741,16 +741,17 @@ def copy(self, deep=True): Parameters ---------- - deep : boolean o rstring, default True + deep : bool or string, default True If False, return shallow copy (do not copy data) If 'all', copy data and a deep copy of the index Returns ------- - copy : BlockManager + BlockManager """ # this preserves the notion of view copying of axes if deep: + # hit in e.g. tests.io.json.test_pandas def copy_func(ax): if deep == "all": @@ -761,6 +762,7 @@ def copy_func(ax): new_axes = [copy_func(ax) for ax in self.axes] else: new_axes = list(self.axes) + res = self.apply("copy", deep=deep) res.axes = new_axes return res diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 2a6da18096c84..6da13f188357c 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -241,12 +241,6 @@ def _iter_data(self, data=None, keep_index=False, fillna=None): if fillna is not None: data = data.fillna(fillna) - # TODO: unused? - # if self.sort_columns: - # columns = com.try_sort(data.columns) - # else: - # columns = data.columns - for col, values in data.items(): if keep_index is True: yield col, values From 77201d771c13ec89ef49e7b6151e0bdcf0359203 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Dec 2019 07:31:18 -0800 Subject: [PATCH 05/11] fix typo form 30414 --- pandas/tests/frame/methods/test_to_records.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_to_records.py b/pandas/tests/frame/methods/test_to_records.py index eb69e8b297a6a..18f77088677ec 100644 --- a/pandas/tests/frame/methods/test_to_records.py +++ b/pandas/tests/frame/methods/test_to_records.py @@ -74,7 +74,7 @@ def test_to_records_with_unicode_index(self): tm.assert_almost_equal(result, expected) def test_to_records_with_unicode_column_names(self): - # xref GH#2407 + # xref issue: https://github.com/numpy/numpy/issues/2407 # Issue GH#11879. to_records used to raise an exception when used # with column names containing non-ascii characters in Python 2 result = DataFrame(data={"accented_name_é": [1.0]}).to_records() From ca8f49488768f4efbd442f7e10fc6776b000f92f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Dec 2019 10:24:53 -0800 Subject: [PATCH 06/11] remove binstar --- .binstar.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .binstar.yml diff --git a/.binstar.yml b/.binstar.yml deleted file mode 100644 index 7b507b4f90049..0000000000000 --- a/.binstar.yml +++ /dev/null @@ -1,28 +0,0 @@ -package: pandas -user: jreback - -install: - - conda config --add channels pandas - -before_script: - - python -V - -platform: - - linux-64 - #- linux-32 - - osx-64 - #- win-32 - - win-64 -engine: - - python=2.7 - - python=3.4 -script: - - conda build conda.recipe --quiet - -iotimeout: 600 - -build_targets: conda - -notifications: - email: - recipients: ['jeff@reback.net'] From 93b901b8ca1ff2a521dc0df4aaf77056aa5e1490 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 24 Dec 2019 09:30:39 -0800 Subject: [PATCH 07/11] catch trueiv warnings, taken from #30345 --- pandas/tests/computation/test_eval.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index e8b6491c5026c..8438eea84baa8 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1206,25 +1206,33 @@ def test_truediv(self): ex = "s / 1" d = {"s": s} # noqa - res = self.eval(ex, truediv=False) + # FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be + # removed in a future version. + with tm.assert_produces_warning(FutureWarning): + res = self.eval(ex, truediv=False) tm.assert_numpy_array_equal(res, np.array([1.0])) - res = self.eval(ex, truediv=True) + with tm.assert_produces_warning(FutureWarning): + res = self.eval(ex, truediv=True) tm.assert_numpy_array_equal(res, np.array([1.0])) - res = self.eval("1 / 2", truediv=True) + with tm.assert_produces_warning(FutureWarning): + res = self.eval("1 / 2", truediv=True) expec = 0.5 assert res == expec - res = self.eval("1 / 2", truediv=False) + with tm.assert_produces_warning(FutureWarning): + res = self.eval("1 / 2", truediv=False) expec = 0.5 assert res == expec - res = self.eval("s / 2", truediv=False) + with tm.assert_produces_warning(FutureWarning): + res = self.eval("s / 2", truediv=False) expec = 0.5 assert res == expec - res = self.eval("s / 2", truediv=True) + with tm.assert_produces_warning(FutureWarning): + res = self.eval("s / 2", truediv=True) expec = 0.5 assert res == expec From 61d2e24da4e4d5437a87d832adb96e3a2515997e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 24 Dec 2019 11:54:30 -0800 Subject: [PATCH 08/11] dont catch importerror --- pandas/tests/dtypes/test_inference.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index f34a6effcc4f5..c9c80e847d6a7 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1123,18 +1123,15 @@ def test_is_string_array(self): def test_to_object_array_tuples(self): r = (5, 6) values = [r] - result = lib.to_object_array_tuples(values) - - try: - # make sure record array works - from collections import namedtuple - - record = namedtuple("record", "x y") - r = record(5, 6) - values = [r] - result = lib.to_object_array_tuples(values) # noqa - except ImportError: - pass + lib.to_object_array_tuples(values) + + # make sure record array works + from collections import namedtuple + + record = namedtuple("record", "x y") + r = record(5, 6) + values = [r] + lib.to_object_array_tuples(values) def test_object(self): From 73d4f99f6179fda1b63f46a8ef33de8faf816855 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 24 Dec 2019 13:44:02 -0800 Subject: [PATCH 09/11] revert bit in another PR --- pandas/tests/io/excel/test_readers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 73f2ee004f50a..480407664285f 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -77,7 +77,7 @@ def cd_and_set_engine(self, engine, datapath, monkeypatch, read_ext): pytest.skip() if engine == "odf" and read_ext != ".ods": pytest.skip() - if engine != "odf" and read_ext == ".ods": + if read_ext == ".ods" and engine != "odf": pytest.skip() func = partial(pd.read_excel, engine=engine) @@ -810,11 +810,11 @@ def cd_and_set_engine(self, engine, datapath, monkeypatch, read_ext): """ Change directory and set engine for ExcelFile objects. """ - if engine == "openpyxl" and read_ext == ".xls": - pytest.skip() if engine == "odf" and read_ext != ".ods": pytest.skip() - if engine != "odf" and read_ext == ".ods": + if read_ext == ".ods" and engine != "odf": + pytest.skip() + if engine == "openpyxl" and read_ext == ".xls": pytest.skip() func = partial(pd.ExcelFile, engine=engine) From 751c9e95f4d7df8a2c419b3052ed65017a463b94 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 25 Dec 2019 15:14:25 -0800 Subject: [PATCH 10/11] black fixup --- pandas/tests/extension/test_numpy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index 1d6b53b754ac9..beb3fc80eccd6 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -106,7 +106,9 @@ def data_for_grouping(allow_in_pandas, dtype): a, b, c = (1,), (2,), (3,) else: a, b, c = np.arange(3) - return PandasArray(np.array([b, b, np.nan, np.nan, a, a, b, c], dtype=dtype.numpy_dtype)) + return PandasArray( + np.array([b, b, np.nan, np.nan, a, a, b, c], dtype=dtype.numpy_dtype) + ) @pytest.fixture From 9508b8d7dd98df6bafd930e1a80582043381764b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 25 Dec 2019 16:09:57 -0800 Subject: [PATCH 11/11] remove runtime imports --- pandas/tests/dtypes/test_inference.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index c9c80e847d6a7..343dcc6849af6 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -4,6 +4,7 @@ """ import collections +from collections import namedtuple from datetime import date, datetime, time, timedelta from decimal import Decimal from fractions import Fraction @@ -1126,8 +1127,6 @@ def test_to_object_array_tuples(self): lib.to_object_array_tuples(values) # make sure record array works - from collections import namedtuple - record = namedtuple("record", "x y") r = record(5, 6) values = [r] @@ -1171,8 +1170,6 @@ def test_is_period(self): def test_categorical(self): # GH 8974 - from pandas import Categorical, Series - arr = Categorical(list("abc")) result = lib.infer_dtype(arr, skipna=True) assert result == "categorical"