From a5719e80961f58cf2edb369c08f0c1864b99872d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 14 Apr 2020 20:28:52 +0100 Subject: [PATCH 1/3] CLN: misc cleanups from LGTM --- pandas/_testing.py | 6 ------ pandas/core/frame.py | 1 - pandas/core/series.py | 1 - 3 files changed, 8 deletions(-) diff --git a/pandas/_testing.py b/pandas/_testing.py index 1f6b645c821c8..e02188f4fb9b1 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -248,16 +248,10 @@ def write_to_compressed(compression, path, data, dest="test"): ValueError : An invalid compression value was passed in. """ if compression == "zip": - import zipfile - compress_method = zipfile.ZipFile elif compression == "gzip": - import gzip - compress_method = gzip.GzipFile elif compression == "bz2": - import bz2 - compress_method = bz2.BZ2File elif compression == "xz": compress_method = _get_lzma_file(lzma) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d19f1a263f71a..dd1aabaa342ff 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8216,7 +8216,6 @@ def blk_func(values): result = result.iloc[0].rename(None) return result - data = self if numeric_only is None: data = self values = data.values diff --git a/pandas/core/series.py b/pandas/core/series.py index 3f5927828e541..66bccb8840cd2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -276,7 +276,6 @@ def __init__( "Cannot construct a Series from an ndarray with " "compound dtype. Use DataFrame instead." ) - pass elif isinstance(data, ABCSeries): if index is None: index = data.index From 66c6768d7130ecee414beffa13ff099610e2193a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 22 Apr 2020 20:19:26 +0100 Subject: [PATCH 2/3] TST: pd.concat on two (or more) series produces all-NaN dataframe --- pandas/tests/reshape/test_concat.py | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index bccae2c4c2772..c4025640bb49f 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -2768,3 +2768,37 @@ def test_concat_copy_index(test_series, axis): comb = concat([df, df], axis=axis, copy=True) assert comb.index is not df.index assert comb.columns is not df.columns + + +def test_concat_multiindex_datetime_object_index(): + # https://github.com/pandas-dev/pandas/issues/11058 + s = Series( + ["a", "b"], + index=MultiIndex.from_arrays( + [[1, 2], Index([dt.date(2013, 1, 1), dt.date(2014, 1, 1)], dtype="object")], + names=["first", "second"], + ), + ) + s2 = Series( + ["a", "b"], + index=MultiIndex.from_arrays( + [[1, 2], Index([dt.date(2013, 1, 1), dt.date(2015, 1, 1)], dtype="object")], + names=["first", "second"], + ), + ) + expected = DataFrame( + [["a", "a"], ["b", np.nan], [np.nan, "b"]], + index=MultiIndex.from_arrays( + [ + [1, 2, 2], + DatetimeIndex( + ["2013-01-01", "2014-01-01", "2015-01-01"], + dtype="datetime64[ns]", + freq=None, + ), + ], + names=["first", "second"], + ), + ) + result = concat([s, s2], axis=1) + tm.assert_frame_equal(result, expected) From 9fab09250b48480beea6dee9e36151e01b738e1f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 22 Apr 2020 20:21:35 +0100 Subject: [PATCH 3/3] Revert "CLN: misc cleanups from LGTM" This reverts commit a5719e80961f58cf2edb369c08f0c1864b99872d. --- pandas/_testing.py | 6 ++++++ pandas/core/frame.py | 1 + pandas/core/series.py | 1 + 3 files changed, 8 insertions(+) diff --git a/pandas/_testing.py b/pandas/_testing.py index 21e74dafcc944..4f957b7a55e3a 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -279,10 +279,16 @@ def write_to_compressed(compression, path, data, dest="test"): ValueError : An invalid compression value was passed in. """ if compression == "zip": + import zipfile + compress_method = zipfile.ZipFile elif compression == "gzip": + import gzip + compress_method = gzip.GzipFile elif compression == "bz2": + import bz2 + compress_method = bz2.BZ2File elif compression == "xz": compress_method = _get_lzma_file(lzma) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d0276af2e9948..202cb6488446e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8218,6 +8218,7 @@ def blk_func(values): result = result.iloc[0].rename(None) return result + data = self if numeric_only is None: data = self values = data.values diff --git a/pandas/core/series.py b/pandas/core/series.py index a9db60f23f2e2..9ef865a964123 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -275,6 +275,7 @@ def __init__( "Cannot construct a Series from an ndarray with " "compound dtype. Use DataFrame instead." ) + pass elif isinstance(data, ABCSeries): if index is None: index = data.index