@@ -342,10 +342,7 @@ def convert_delta_safe(base, deltas, unit) -> Series:
342342 has_bad_values = False
343343 if bad_locs .any ():
344344 has_bad_values = True
345- # reset cache to avoid SettingWithCopy checks (we own the DataFrame and the
346- # `dates` Series is used to overwrite itself in the DataFramae)
347- dates ._reset_cacher ()
348- dates [bad_locs ] = 1.0 # Replace with NaT
345+ dates ._values [bad_locs ] = 1.0 # Replace with NaT
349346 dates = dates .astype (np .int64 )
350347
351348 if fmt .startswith (("%tc" , "tc" )): # Delta ms relative to base
@@ -462,11 +459,10 @@ def g(x: datetime) -> int:
462459 bad_loc = isna (dates )
463460 index = dates .index
464461 if bad_loc .any ():
465- dates = Series (dates )
466462 if lib .is_np_dtype (dates .dtype , "M" ):
467- dates [bad_loc ] = to_datetime (stata_epoch )
463+ dates . _values [bad_loc ] = to_datetime (stata_epoch )
468464 else :
469- dates [bad_loc ] = stata_epoch
465+ dates . _values [bad_loc ] = stata_epoch
470466
471467 if fmt in ["%tc" , "tc" ]:
472468 d = parse_dates_safe (dates , delta = True )
@@ -596,9 +592,8 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame:
596592 for col in data :
597593 # Cast from unsupported types to supported types
598594 is_nullable_int = isinstance (data [col ].dtype , (IntegerDtype , BooleanDtype ))
599- orig = data [col ]
600595 # We need to find orig_missing before altering data below
601- orig_missing = orig .isna ()
596+ orig_missing = data [ col ] .isna ()
602597 if is_nullable_int :
603598 missing_loc = data [col ].isna ()
604599 if missing_loc .any ():
@@ -1780,15 +1775,15 @@ def read(
17801775 for idx in valid_dtypes :
17811776 dtype = data .iloc [:, idx ].dtype
17821777 if dtype not in (object_type , self ._dtyplist [idx ]):
1783- data .iloc [:, idx ] = data .iloc [:, idx ].astype (dtype )
1778+ data .isetitem ( idx , data .iloc [:, idx ].astype (dtype ) )
17841779
17851780 data = self ._do_convert_missing (data , convert_missing )
17861781
17871782 if convert_dates :
17881783 for i , fmt in enumerate (self ._fmtlist ):
17891784 if any (fmt .startswith (date_fmt ) for date_fmt in _date_formats ):
1790- data .iloc [:, i ] = _stata_elapsed_date_to_datetime_vec (
1791- data .iloc [:, i ], fmt
1785+ data .isetitem (
1786+ i , _stata_elapsed_date_to_datetime_vec ( data .iloc [:, i ], fmt )
17921787 )
17931788
17941789 if convert_categoricals and self ._format_version > 108 :
@@ -1863,7 +1858,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
18631858 replacements [i ] = replacement
18641859 if replacements :
18651860 for idx , value in replacements .items ():
1866- data .iloc [:, idx ] = value
1861+ data .isetitem ( idx , value )
18671862 return data
18681863
18691864 def _insert_strls (self , data : DataFrame ) -> DataFrame :
@@ -1873,7 +1868,7 @@ def _insert_strls(self, data: DataFrame) -> DataFrame:
18731868 if typ != "Q" :
18741869 continue
18751870 # Wrap v_o in a string to allow uint64 values as keys on 32bit OS
1876- data .iloc [:, i ] = [self .GSO [str (k )] for k in data .iloc [:, i ]]
1871+ data .isetitem ( i , [self .GSO [str (k )] for k in data .iloc [:, i ]])
18771872 return data
18781873
18791874 def _do_select_columns (self , data : DataFrame , columns : Sequence [str ]) -> DataFrame :
0 commit comments