@@ -342,10 +342,7 @@ def convert_delta_safe(base, deltas, unit) -> Series:
342
342
has_bad_values = False
343
343
if bad_locs .any ():
344
344
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
349
346
dates = dates .astype (np .int64 )
350
347
351
348
if fmt .startswith (("%tc" , "tc" )): # Delta ms relative to base
@@ -462,11 +459,10 @@ def g(x: datetime) -> int:
462
459
bad_loc = isna (dates )
463
460
index = dates .index
464
461
if bad_loc .any ():
465
- dates = Series (dates )
466
462
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 )
468
464
else :
469
- dates [bad_loc ] = stata_epoch
465
+ dates . _values [bad_loc ] = stata_epoch
470
466
471
467
if fmt in ["%tc" , "tc" ]:
472
468
d = parse_dates_safe (dates , delta = True )
@@ -596,9 +592,8 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame:
596
592
for col in data :
597
593
# Cast from unsupported types to supported types
598
594
is_nullable_int = isinstance (data [col ].dtype , (IntegerDtype , BooleanDtype ))
599
- orig = data [col ]
600
595
# We need to find orig_missing before altering data below
601
- orig_missing = orig .isna ()
596
+ orig_missing = data [ col ] .isna ()
602
597
if is_nullable_int :
603
598
missing_loc = data [col ].isna ()
604
599
if missing_loc .any ():
@@ -1780,15 +1775,15 @@ def read(
1780
1775
for idx in valid_dtypes :
1781
1776
dtype = data .iloc [:, idx ].dtype
1782
1777
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 ) )
1784
1779
1785
1780
data = self ._do_convert_missing (data , convert_missing )
1786
1781
1787
1782
if convert_dates :
1788
1783
for i , fmt in enumerate (self ._fmtlist ):
1789
1784
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 )
1792
1787
)
1793
1788
1794
1789
if convert_categoricals and self ._format_version > 108 :
@@ -1863,7 +1858,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
1863
1858
replacements [i ] = replacement
1864
1859
if replacements :
1865
1860
for idx , value in replacements .items ():
1866
- data .iloc [:, idx ] = value
1861
+ data .isetitem ( idx , value )
1867
1862
return data
1868
1863
1869
1864
def _insert_strls (self , data : DataFrame ) -> DataFrame :
@@ -1873,7 +1868,7 @@ def _insert_strls(self, data: DataFrame) -> DataFrame:
1873
1868
if typ != "Q" :
1874
1869
continue
1875
1870
# 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 ]])
1877
1872
return data
1878
1873
1879
1874
def _do_select_columns (self , data : DataFrame , columns : Sequence [str ]) -> DataFrame :
0 commit comments