@@ -48,6 +48,18 @@ def numpy(request):
48
48
return request .param
49
49
50
50
51
+ def get_int32_compat_dtype (numpy , orient ):
52
+ # See GH#32527
53
+ dtype = np .int64
54
+ if not ((numpy is None or orient == "index" ) or (numpy is True and orient is None )):
55
+ if compat .is_platform_windows ():
56
+ dtype = np .int32
57
+ else :
58
+ dtype = np .intp
59
+
60
+ return dtype
61
+
62
+
51
63
class TestUltraJSONTests :
52
64
@pytest .mark .skipif (
53
65
compat .is_platform_32bit (), reason = "not compliant on 32-bit, xref #15865"
@@ -833,13 +845,20 @@ def test_dataframe(self, orient, numpy):
833
845
if orient == "records" and numpy :
834
846
pytest .skip ("Not idiomatic pandas" )
835
847
848
+ dtype = get_int32_compat_dtype (numpy , orient )
849
+
836
850
df = DataFrame (
837
- [[1 , 2 , 3 ], [4 , 5 , 6 ]], index = ["a" , "b" ], columns = ["x" , "y" , "z" ]
851
+ [[1 , 2 , 3 ], [4 , 5 , 6 ]],
852
+ index = ["a" , "b" ],
853
+ columns = ["x" , "y" , "z" ],
854
+ dtype = dtype ,
838
855
)
839
856
encode_kwargs = {} if orient is None else dict (orient = orient )
840
857
decode_kwargs = {} if numpy is None else dict (numpy = numpy )
858
+ assert (df .dtypes == dtype ).all ()
841
859
842
860
output = ujson .decode (ujson .encode (df , ** encode_kwargs ), ** decode_kwargs )
861
+ assert (df .dtypes == dtype ).all ()
843
862
844
863
# Ensure proper DataFrame initialization.
845
864
if orient == "split" :
@@ -857,7 +876,8 @@ def test_dataframe(self, orient, numpy):
857
876
elif orient == "index" :
858
877
df = df .transpose ()
859
878
860
- tm .assert_frame_equal (output , df , check_dtype = False )
879
+ assert (df .dtypes == dtype ).all ()
880
+ tm .assert_frame_equal (output , df )
861
881
862
882
def test_dataframe_nested (self , orient ):
863
883
df = DataFrame (
@@ -897,14 +917,20 @@ def test_dataframe_numpy_labelled(self, orient):
897
917
tm .assert_frame_equal (output , df )
898
918
899
919
def test_series (self , orient , numpy ):
920
+ dtype = get_int32_compat_dtype (numpy , orient )
900
921
s = Series (
901
- [10 , 20 , 30 , 40 , 50 , 60 ], name = "series" , index = [6 , 7 , 8 , 9 , 10 , 15 ]
922
+ [10 , 20 , 30 , 40 , 50 , 60 ],
923
+ name = "series" ,
924
+ index = [6 , 7 , 8 , 9 , 10 , 15 ],
925
+ dtype = dtype ,
902
926
).sort_values ()
927
+ assert s .dtype == dtype
903
928
904
929
encode_kwargs = {} if orient is None else dict (orient = orient )
905
930
decode_kwargs = {} if numpy is None else dict (numpy = numpy )
906
931
907
932
output = ujson .decode (ujson .encode (s , ** encode_kwargs ), ** decode_kwargs )
933
+ assert s .dtype == dtype
908
934
909
935
if orient == "split" :
910
936
dec = _clean_dict (output )
@@ -920,7 +946,8 @@ def test_series(self, orient, numpy):
920
946
s .name = None
921
947
s .index = [0 , 1 , 2 , 3 , 4 , 5 ]
922
948
923
- tm .assert_series_equal (output , s , check_dtype = False )
949
+ assert s .dtype == dtype
950
+ tm .assert_series_equal (output , s )
924
951
925
952
def test_series_nested (self , orient ):
926
953
s = Series (
0 commit comments