Skip to content

Commit fbebef7

Browse files
authored
Support inclusive argument for pd.date_range (#2718)
1 parent b5be4e7 commit fbebef7

File tree

12 files changed

+185
-141
lines changed

12 files changed

+185
-141
lines changed

mars/dataframe/arithmetic/tests/test_arithmetic.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def test_without_shuffle(func_name, func_opts):
176176
assert df3.columns_value.should_be_monotonic is True
177177
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
178178
assert df3.index_value.should_be_monotonic is True
179-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
179+
pd.testing.assert_index_equal(
180+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
181+
)
180182
assert df3.index_value.key != df1.index_value.key
181183
assert df3.index_value.key != df2.index_value.key
182184
assert df3.shape[1] == 11 # columns is recorded, so we can get it
@@ -190,7 +192,9 @@ def test_without_shuffle(func_name, func_opts):
190192
assert df3.columns_value.should_be_monotonic is True
191193
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
192194
assert df3.index_value.should_be_monotonic is True
193-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
195+
pd.testing.assert_index_equal(
196+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
197+
)
194198
assert df3.index_value.key != df1.index_value.key
195199
assert df3.index_value.key != df2.index_value.key
196200
assert df3.shape[1] == 11 # columns is recorded, so we can get it
@@ -408,7 +412,9 @@ def test_dataframe_and_series_with_shuffle(func_name, func_opts):
408412
# test df2's index and columns
409413
assert df2.shape == (df1.shape[0], np.nan)
410414
assert df2.index_value.key == df1.index_value.key
411-
pd.testing.assert_index_equal(df2.columns_value.to_pandas(), pd.Int64Index([]))
415+
pd.testing.assert_index_equal(
416+
df2.columns_value.to_pandas(), pd.Index([], dtype=np.int64)
417+
)
412418
assert df2.columns_value.key != df1.columns_value.key
413419
assert df2.columns_value.should_be_monotonic is True
414420

@@ -602,7 +608,9 @@ def test_series_and_series_with_shuffle(func_name, func_opts):
602608
assert s3.shape == (np.nan,)
603609
assert s3.index_value.key != s1.index_value.key
604610
assert s3.index_value.key != s2.index_value.key
605-
pd.testing.assert_index_equal(s3.index_value.to_pandas(), pd.Int64Index([]))
611+
pd.testing.assert_index_equal(
612+
s3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
613+
)
606614
assert s3.index_value.should_be_monotonic is True
607615

608616
s1, s2, s3 = tile(s1, s2, s3)
@@ -726,7 +734,9 @@ def test_with_one_shuffle(func_name, func_opts):
726734
assert df3.columns_value.should_be_monotonic is True
727735
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
728736
assert df3.index_value.should_be_monotonic is True
729-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
737+
pd.testing.assert_index_equal(
738+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
739+
)
730740
assert df3.index_value.key != df1.index_value.key
731741
assert df3.index_value.key != df2.index_value.key
732742
assert df3.shape[1] == 12 # columns is recorded, so we can get it
@@ -858,7 +868,9 @@ def test_with_all_shuffle(func_name, func_opts):
858868
assert df3.columns_value.should_be_monotonic is True
859869
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
860870
assert df3.index_value.should_be_monotonic is True
861-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
871+
pd.testing.assert_index_equal(
872+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
873+
)
862874
assert df3.index_value.key != df1.index_value.key
863875
assert df3.index_value.key != df2.index_value.key
864876
assert df3.shape[1] == 12 # columns is recorded, so we can get it
@@ -958,7 +970,9 @@ def test_with_all_shuffle(func_name, func_opts):
958970
assert df6.columns_value.should_be_monotonic is True
959971
assert isinstance(df6.index_value.value, IndexValue.Int64Index)
960972
assert df6.index_value.should_be_monotonic is True
961-
pd.testing.assert_index_equal(df6.index_value.to_pandas(), pd.Int64Index([]))
973+
pd.testing.assert_index_equal(
974+
df6.index_value.to_pandas(), pd.Index([], dtype=np.int64)
975+
)
962976
assert df6.index_value.key != df4.index_value.key
963977
assert df6.index_value.key != df5.index_value.key
964978
assert df6.shape[1] == 20 # columns is recorded, so we can get it
@@ -1063,7 +1077,9 @@ def test_without_shuffle_and_with_one_chunk(func_name, func_opts):
10631077
assert df3.columns_value.should_be_monotonic is True
10641078
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
10651079
assert df3.index_value.should_be_monotonic is True
1066-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
1080+
pd.testing.assert_index_equal(
1081+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
1082+
)
10671083
assert df3.index_value.key != df1.index_value.key
10681084
assert df3.index_value.key != df2.index_value.key
10691085
assert df3.shape[1] == 12 # columns is recorded, so we can get it
@@ -1175,7 +1191,9 @@ def test_both_one_chunk(func_name, func_opts):
11751191
assert df3.columns_value.should_be_monotonic is True
11761192
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
11771193
assert df3.index_value.should_be_monotonic is True
1178-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
1194+
pd.testing.assert_index_equal(
1195+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
1196+
)
11791197
assert df3.index_value.key != df1.index_value.key
11801198
assert df3.index_value.key != df2.index_value.key
11811199
assert df3.shape[1] == 12 # columns is recorded, so we can get it
@@ -1219,7 +1237,9 @@ def test_with_shuffle_and_one_chunk(func_name, func_opts):
12191237
assert df3.columns_value.should_be_monotonic is True
12201238
assert isinstance(df3.index_value.value, IndexValue.Int64Index)
12211239
assert df3.index_value.should_be_monotonic is True
1222-
pd.testing.assert_index_equal(df3.index_value.to_pandas(), pd.Int64Index([]))
1240+
pd.testing.assert_index_equal(
1241+
df3.index_value.to_pandas(), pd.Index([], dtype=np.int64)
1242+
)
12231243
assert df3.index_value.key != df1.index_value.key
12241244
assert df3.index_value.key != df2.index_value.key
12251245
assert df3.shape[1] == 12 # columns is recorded, so we can get it
@@ -1312,7 +1332,9 @@ def test_on_same_dataframe(func_name, func_opts):
13121332
assert df2.columns_value.should_be_monotonic is False
13131333
assert isinstance(df2.index_value.value, IndexValue.Int64Index)
13141334
assert df2.index_value.should_be_monotonic is False
1315-
pd.testing.assert_index_equal(df2.index_value.to_pandas(), pd.Int64Index([]))
1335+
pd.testing.assert_index_equal(
1336+
df2.index_value.to_pandas(), pd.Index([], dtype=np.int64)
1337+
)
13161338
assert df2.index_value.key == df.index_value.key
13171339
assert df2.columns_value.key == df.columns_value.key
13181340
assert df2.shape[1] == 10

mars/dataframe/core.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def to_pandas(self):
138138
kw = {k: v for k, v in kw.items() if v is not None}
139139
if kw.get("data") is None:
140140
kw["data"] = []
141-
return getattr(pd, type(self).__name__)(**kw)
141+
142+
pd_initializer = getattr(self, "_pd_initializer", None)
143+
if pd_initializer is None:
144+
pd_initializer = getattr(pd, type(self).__name__)
145+
return pd_initializer(**kw)
142146

143147
class Index(IndexBase):
144148
_name = AnyField("name")
@@ -240,6 +244,8 @@ def inferred_type(self):
240244
return "period"
241245

242246
class Int64Index(IndexBase):
247+
_pd_initializer = pd.Index
248+
243249
_name = AnyField("name")
244250
_data = NDArrayField("data")
245251
_dtype = DataTypeField("dtype")
@@ -249,6 +255,8 @@ def inferred_type(self):
249255
return "integer"
250256

251257
class UInt64Index(IndexBase):
258+
_pd_initializer = pd.Index
259+
252260
_name = AnyField("name")
253261
_data = NDArrayField("data")
254262
_dtype = DataTypeField("dtype")
@@ -258,6 +266,8 @@ def inferred_type(self):
258266
return "integer"
259267

260268
class Float64Index(IndexBase):
269+
_pd_initializer = pd.Index
270+
261271
_name = AnyField("name")
262272
_data = NDArrayField("data")
263273
_dtype = DataTypeField("dtype")

0 commit comments

Comments
 (0)