Skip to content

Commit c15ca51

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into cln-idx
2 parents 87f5311 + 6752833 commit c15ca51

File tree

15 files changed

+87
-89
lines changed

15 files changed

+87
-89
lines changed

pandas/core/indexes/multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ def drop(self, codes, level=None, errors="raise"):
20582058

20592059
if not isinstance(codes, (np.ndarray, Index)):
20602060
try:
2061-
codes = com.index_labels_to_array(codes)
2061+
codes = com.index_labels_to_array(codes, dtype=object)
20622062
except ValueError:
20632063
pass
20642064

pandas/core/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def cat_core(list_of_columns: List, sep: str):
7979
return np.sum(arr_of_cols, axis=0)
8080
list_with_sep = [sep] * (2 * len(list_of_columns) - 1)
8181
list_with_sep[::2] = list_of_columns
82-
arr_with_sep = np.asarray(list_with_sep)
82+
arr_with_sep = np.asarray(list_with_sep, dtype=object)
8383
return np.sum(arr_with_sep, axis=0)
8484

8585

pandas/io/pytables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ class Fixed:
24722472
"""
24732473

24742474
pandas_kind: str
2475+
format_type: str = "fixed" # GH#30962 needed by dask
24752476
obj_type: Type[Union[DataFrame, Series]]
24762477
ndim: int
24772478
encoding: str
@@ -3129,6 +3130,7 @@ class Table(Fixed):
31293130
"""
31303131

31313132
pandas_kind = "wide_table"
3133+
format_type: str = "table" # GH#30962 needed by dask
31323134
table_type: str
31333135
levels = 1
31343136
is_table = True

pandas/tests/arrays/categorical/test_constructors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,6 @@ def test_constructor_imaginary(self):
605605
@pytest.mark.skipif(_np_version_under1p16, reason="Skipping for NumPy <1.16")
606606
def test_constructor_string_and_tuples(self):
607607
# GH 21416
608-
c = pd.Categorical(["c", ("a", "b"), ("b", "a"), "c"])
608+
c = pd.Categorical(np.array(["c", ("a", "b"), ("b", "a"), "c"], dtype=object))
609609
expected_index = pd.Index([("a", "b"), ("b", "a"), "c"])
610610
assert c.categories.equals(expected_index)

pandas/tests/arrays/categorical/test_missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_fillna_iterable_category(self, named):
7777
Point = collections.namedtuple("Point", "x y")
7878
else:
7979
Point = lambda *args: args # tuple
80-
cat = Categorical([Point(0, 0), Point(0, 1), None])
80+
cat = Categorical(np.array([Point(0, 0), Point(0, 1), None], dtype=object))
8181
result = cat.fillna(Point(0, 0))
8282
expected = Categorical([Point(0, 0), Point(0, 1), Point(0, 0)])
8383

pandas/tests/extension/base/getitem.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ def test_take_non_na_fill_value(self, data_missing):
245245
fill_value = data_missing[1] # valid
246246
na = data_missing[0]
247247

248-
array = data_missing._from_sequence([na, fill_value, na])
248+
array = data_missing._from_sequence(
249+
[na, fill_value, na], dtype=data_missing.dtype
250+
)
249251
result = array.take([-1, 1], fill_value=fill_value, allow_fill=True)
250252
expected = array.take([1, 1])
251253
self.assert_extension_array_equal(result, expected)
@@ -293,10 +295,12 @@ def test_reindex_non_na_fill_value(self, data_missing):
293295
valid = data_missing[1]
294296
na = data_missing[0]
295297

296-
array = data_missing._from_sequence([na, valid])
298+
array = data_missing._from_sequence([na, valid], dtype=data_missing.dtype)
297299
ser = pd.Series(array)
298300
result = ser.reindex([0, 1, 2], fill_value=valid)
299-
expected = pd.Series(data_missing._from_sequence([na, valid, valid]))
301+
expected = pd.Series(
302+
data_missing._from_sequence([na, valid, valid], dtype=data_missing.dtype)
303+
)
300304

301305
self.assert_series_equal(result, expected)
302306

pandas/tests/extension/json/array.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def __setitem__(self, key, value):
113113
def __len__(self) -> int:
114114
return len(self.data)
115115

116+
def __array__(self, dtype=None):
117+
if dtype is None:
118+
dtype = object
119+
return np.asarray(self.data, dtype=dtype)
120+
116121
@property
117122
def nbytes(self) -> int:
118123
return sys.getsizeof(self.data)

pandas/tests/extension/json/test_json.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ def test_unstack(self, data, index):
163163
# this matches otherwise
164164
return super().test_unstack(data, index)
165165

166-
@pytest.mark.xfail(reason="Inconsistent sizes.")
167-
def test_transpose(self, data):
168-
super().test_transpose(data)
169-
170166

171167
class TestGetitem(BaseJSON, base.BaseGetitemTests):
172168
pass

pandas/tests/indexes/conftest.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import numpy as np
21
import pytest
32

4-
import pandas as pd
53
import pandas._testing as tm
64
from pandas.core.indexes.api import Index, MultiIndex
75

@@ -28,25 +26,3 @@
2826
def indices(request):
2927
# copy to avoid mutation, e.g. setting .name
3028
return indices_dict[request.param].copy()
31-
32-
33-
@pytest.fixture(params=[1, np.array(1, dtype=np.int64)])
34-
def one(request):
35-
# zero-dim integer array behaves like an integer
36-
return request.param
37-
38-
39-
zeros = [
40-
box([0] * 5, dtype=dtype)
41-
for box in [pd.Index, np.array]
42-
for dtype in [np.int64, np.uint64, np.float64]
43-
]
44-
zeros.extend([np.array(0, dtype=dtype) for dtype in [np.int64, np.uint64, np.float64]])
45-
zeros.extend([0, 0.0])
46-
47-
48-
@pytest.fixture(params=zeros)
49-
def zero(request):
50-
# For testing division by (or of) zero for Index with length 5, this
51-
# gives several scalar-zeros and length-5 vector-zeros
52-
return request.param
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from pandas import DatetimeIndex, date_range
4+
import pandas._testing as tm
5+
6+
7+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
8+
@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"])
9+
@pytest.mark.parametrize("name", [None, "my_dti"])
10+
def test_dti_snap(name, tz):
11+
dti = DatetimeIndex(
12+
[
13+
"1/1/2002",
14+
"1/2/2002",
15+
"1/3/2002",
16+
"1/4/2002",
17+
"1/5/2002",
18+
"1/6/2002",
19+
"1/7/2002",
20+
],
21+
name=name,
22+
tz=tz,
23+
freq="D",
24+
)
25+
26+
result = dti.snap(freq="W-MON")
27+
expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon")
28+
expected = expected.repeat([3, 4])
29+
tm.assert_index_equal(result, expected)
30+
assert result.tz == expected.tz
31+
32+
result = dti.snap(freq="B")
33+
34+
expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
35+
expected = expected.repeat([1, 1, 1, 2, 2])
36+
tm.assert_index_equal(result, expected)
37+
assert result.tz == expected.tz

pandas/tests/indexes/multi/test_setops.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def test_symmetric_difference(idx, sort):
110110
first.symmetric_difference([1, 2, 3], sort=sort)
111111

112112

113+
def test_multiindex_symmetric_difference():
114+
# GH 13490
115+
idx = MultiIndex.from_product([["a", "b"], ["A", "B"]], names=["a", "b"])
116+
result = idx ^ idx
117+
assert result.names == idx.names
118+
119+
idx2 = idx.copy().rename(["A", "B"])
120+
result = idx ^ idx2
121+
assert result.names == [None, None]
122+
123+
113124
def test_empty(idx):
114125
# GH 15270
115126
assert not idx.empty

pandas/tests/indexing/multiindex/test_set_ops.py renamed to pandas/tests/indexing/multiindex/test_insert.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
import pandas._testing as tm
55

66

7-
class TestMultiIndexSetOps:
8-
def test_multiindex_symmetric_difference(self):
9-
# GH 13490
10-
idx = MultiIndex.from_product([["a", "b"], ["A", "B"]], names=["a", "b"])
11-
result = idx ^ idx
12-
assert result.names == idx.names
13-
14-
idx2 = idx.copy().rename(["A", "B"])
15-
result = idx ^ idx2
16-
assert result.names == [None, None]
17-
7+
class TestMultiIndexInsertion:
188
def test_mixed_depth_insert(self):
199
arrays = [
2010
["a", "top", "top", "routine1", "routine1", "routine2"],

pandas/tests/io/pytables/test_store.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464

6565
@pytest.mark.single
6666
class TestHDFStore:
67+
def test_format_type(self, setup_path):
68+
df = pd.DataFrame({"A": [1, 2]})
69+
with ensure_clean_path(setup_path) as path:
70+
with HDFStore(path) as store:
71+
store.put("a", df, format="fixed")
72+
store.put("b", df, format="table")
73+
74+
assert store.get_storer("a").format_type == "fixed"
75+
assert store.get_storer("b").format_type == "table"
76+
6777
def test_format_kwarg_in_constructor(self, setup_path):
6878
# GH 13291
6979

pandas/tests/series/indexing/test_datetime.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,6 @@ def test_fancy_setitem():
4949
assert (s[48:54] == -3).all()
5050

5151

52-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
53-
@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"])
54-
@pytest.mark.parametrize("name", [None, "my_dti"])
55-
def test_dti_snap(name, tz):
56-
dti = DatetimeIndex(
57-
[
58-
"1/1/2002",
59-
"1/2/2002",
60-
"1/3/2002",
61-
"1/4/2002",
62-
"1/5/2002",
63-
"1/6/2002",
64-
"1/7/2002",
65-
],
66-
name=name,
67-
tz=tz,
68-
freq="D",
69-
)
70-
71-
result = dti.snap(freq="W-MON")
72-
expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon")
73-
expected = expected.repeat([3, 4])
74-
tm.assert_index_equal(result, expected)
75-
assert result.tz == expected.tz
76-
77-
result = dti.snap(freq="B")
78-
79-
expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
80-
expected = expected.repeat([1, 1, 1, 2, 2])
81-
tm.assert_index_equal(result, expected)
82-
assert result.tz == expected.tz
83-
84-
8552
def test_dti_reset_index_round_trip():
8653
dti = date_range(start="1/1/2001", end="6/1/2001", freq="D")
8754
d1 = DataFrame({"v": np.random.rand(len(dti))}, index=dti)
@@ -751,16 +718,6 @@ def test_nat_operations():
751718
assert s.max() == exp
752719

753720

754-
@pytest.mark.parametrize("method", ["round", "floor", "ceil"])
755-
@pytest.mark.parametrize("freq", ["s", "5s", "min", "5min", "h", "5h"])
756-
def test_round_nat(method, freq):
757-
# GH14940
758-
s = Series([pd.NaT])
759-
expected = Series(pd.NaT)
760-
round_method = getattr(s.dt, method)
761-
tm.assert_series_equal(round_method(freq), expected)
762-
763-
764721
def test_setitem_tuple_with_datetimetz():
765722
# GH 20441
766723
arr = date_range("2017", periods=4, tz="US/Eastern")

pandas/tests/series/methods/test_round.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas as pd
45
from pandas import Series
56
import pandas._testing as tm
67

@@ -44,3 +45,12 @@ def test_round_builtin(self):
4445
expected_rounded = Series([1.12, 2.12, 3.12], index=range(3))
4546
result = round(ser, decimals)
4647
tm.assert_series_equal(result, expected_rounded)
48+
49+
@pytest.mark.parametrize("method", ["round", "floor", "ceil"])
50+
@pytest.mark.parametrize("freq", ["s", "5s", "min", "5min", "h", "5h"])
51+
def test_round_nat(self, method, freq):
52+
# GH14940
53+
ser = Series([pd.NaT])
54+
expected = Series(pd.NaT)
55+
round_method = getattr(ser.dt, method)
56+
tm.assert_series_equal(round_method(freq), expected)

0 commit comments

Comments
 (0)