@@ -513,7 +513,6 @@ def test_read_write_reread_dta14(self, file, parsed_114, version, datapath):
513
513
written_and_read_again = self .read_dta (path )
514
514
515
515
expected = parsed_114 .copy ()
516
- expected .index = expected .index .astype (np .int32 )
517
516
tm .assert_frame_equal (written_and_read_again .set_index ("index" ), expected )
518
517
519
518
@pytest .mark .parametrize (
@@ -576,7 +575,6 @@ def test_numeric_column_names(self):
576
575
written_and_read_again .columns = map (convert_col_name , columns )
577
576
578
577
expected = original
579
- expected .index = expected .index .astype (np .int32 )
580
578
tm .assert_frame_equal (expected , written_and_read_again )
581
579
582
580
@pytest .mark .parametrize ("version" , [114 , 117 , 118 , 119 , None ])
@@ -594,7 +592,6 @@ def test_nan_to_missing_value(self, version):
594
592
595
593
written_and_read_again = written_and_read_again .set_index ("index" )
596
594
expected = original
597
- expected .index = expected .index .astype (np .int32 )
598
595
tm .assert_frame_equal (written_and_read_again , expected )
599
596
600
597
def test_no_index (self ):
@@ -617,7 +614,6 @@ def test_string_no_dates(self):
617
614
written_and_read_again = self .read_dta (path )
618
615
619
616
expected = original
620
- expected .index = expected .index .astype (np .int32 )
621
617
tm .assert_frame_equal (written_and_read_again .set_index ("index" ), expected )
622
618
623
619
def test_large_value_conversion (self ):
@@ -637,7 +633,6 @@ def test_large_value_conversion(self):
637
633
modified ["s1" ] = Series (modified ["s1" ], dtype = np .int16 )
638
634
modified ["s2" ] = Series (modified ["s2" ], dtype = np .int32 )
639
635
modified ["s3" ] = Series (modified ["s3" ], dtype = np .float64 )
640
- modified .index = original .index .astype (np .int32 )
641
636
tm .assert_frame_equal (written_and_read_again .set_index ("index" ), modified )
642
637
643
638
def test_dates_invalid_column (self ):
@@ -713,7 +708,7 @@ def test_write_missing_strings(self):
713
708
714
709
expected = DataFrame (
715
710
[["1" ], ["" ]],
716
- index = pd .Index ([ 0 , 1 ], dtype = np . int32 , name = "index" ),
711
+ index = pd .RangeIndex ( 2 , name = "index" ),
717
712
columns = ["foo" ],
718
713
)
719
714
@@ -746,7 +741,6 @@ def test_bool_uint(self, byteorder, version):
746
741
written_and_read_again = written_and_read_again .set_index ("index" )
747
742
748
743
expected = original
749
- expected .index = expected .index .astype (np .int32 )
750
744
expected_types = (
751
745
np .int8 ,
752
746
np .int8 ,
@@ -1030,7 +1024,7 @@ def test_categorical_writing(self, version):
1030
1024
res = written_and_read_again .set_index ("index" )
1031
1025
1032
1026
expected = original
1033
- expected .index = expected .index .set_names ("index" ). astype ( np . int32 )
1027
+ expected .index = expected .index .set_names ("index" )
1034
1028
1035
1029
expected ["incompletely_labeled" ] = expected ["incompletely_labeled" ].apply (str )
1036
1030
expected ["unlabeled" ] = expected ["unlabeled" ].apply (str )
@@ -1094,7 +1088,6 @@ def test_categorical_with_stata_missing_values(self, version):
1094
1088
new_cats = cat .remove_unused_categories ().categories
1095
1089
cat = cat .set_categories (new_cats , ordered = True )
1096
1090
expected [col ] = cat
1097
- expected .index = expected .index .astype (np .int32 )
1098
1091
tm .assert_frame_equal (res , expected )
1099
1092
1100
1093
@pytest .mark .parametrize ("file" , ["stata10_115" , "stata10_117" ])
@@ -1544,7 +1537,6 @@ def test_out_of_range_float(self):
1544
1537
1545
1538
original ["ColumnTooBig" ] = original ["ColumnTooBig" ].astype (np .float64 )
1546
1539
expected = original
1547
- expected .index = expected .index .astype (np .int32 )
1548
1540
tm .assert_frame_equal (reread .set_index ("index" ), expected )
1549
1541
1550
1542
@pytest .mark .parametrize ("infval" , [np .inf , - np .inf ])
@@ -1669,7 +1661,6 @@ def test_writer_117(self):
1669
1661
original ["int32" ] = original ["int32" ].astype (np .int32 )
1670
1662
original ["float32" ] = Series (original ["float32" ], dtype = np .float32 )
1671
1663
original .index .name = "index"
1672
- original .index = original .index .astype (np .int32 )
1673
1664
copy = original .copy ()
1674
1665
with tm .ensure_clean () as path :
1675
1666
original .to_stata (
@@ -1962,7 +1953,7 @@ def test_read_write_ea_dtypes(self, dtype_backend):
1962
1953
# stata stores with ms unit, so unit does not round-trip exactly
1963
1954
"e" : pd .date_range ("2020-12-31" , periods = 3 , freq = "D" , unit = "ms" ),
1964
1955
},
1965
- index = pd .Index ([ 0 , 1 , 2 ], name = "index" , dtype = np . int32 ),
1956
+ index = pd .RangeIndex ( range ( 3 ), name = "index" ),
1966
1957
)
1967
1958
1968
1959
tm .assert_frame_equal (written_and_read_again .set_index ("index" ), expected )
@@ -2049,7 +2040,6 @@ def test_compression(compression, version, use_dict, infer, compression_to_exten
2049
2040
reread = read_stata (fp , index_col = "index" )
2050
2041
2051
2042
expected = df
2052
- expected .index = expected .index .astype (np .int32 )
2053
2043
tm .assert_frame_equal (reread , expected )
2054
2044
2055
2045
@@ -2075,7 +2065,6 @@ def test_compression_dict(method, file_ext):
2075
2065
reread = read_stata (fp , index_col = "index" )
2076
2066
2077
2067
expected = df
2078
- expected .index = expected .index .astype (np .int32 )
2079
2068
tm .assert_frame_equal (reread , expected )
2080
2069
2081
2070
@@ -2085,7 +2074,6 @@ def test_chunked_categorical(version):
2085
2074
df .index .name = "index"
2086
2075
2087
2076
expected = df .copy ()
2088
- expected .index = expected .index .astype (np .int32 )
2089
2077
2090
2078
with tm .ensure_clean () as path :
2091
2079
df .to_stata (path , version = version )
@@ -2094,7 +2082,9 @@ def test_chunked_categorical(version):
2094
2082
block = block .set_index ("index" )
2095
2083
assert "cats" in block
2096
2084
tm .assert_series_equal (
2097
- block .cats , expected .cats .iloc [2 * i : 2 * (i + 1 )]
2085
+ block .cats ,
2086
+ expected .cats .iloc [2 * i : 2 * (i + 1 )],
2087
+ check_index_type = len (block ) > 1 ,
2098
2088
)
2099
2089
2100
2090
0 commit comments