@@ -1700,13 +1700,6 @@ def read(
1700
1700
order_categoricals : bool | None = None ,
1701
1701
) -> DataFrame :
1702
1702
self ._ensure_open ()
1703
- # Handle empty file or chunk. If reading incrementally raise
1704
- # StopIteration. If reading the whole thing return an empty
1705
- # data frame.
1706
- if (self ._nobs == 0 ) and (nrows is None ):
1707
- self ._can_read_value_labels = True
1708
- self ._data_read = True
1709
- return DataFrame (columns = self ._varlist )
1710
1703
1711
1704
# Handle options
1712
1705
if convert_dates is None :
@@ -1723,10 +1716,24 @@ def read(
1723
1716
order_categoricals = self ._order_categoricals
1724
1717
if index_col is None :
1725
1718
index_col = self ._index_col
1726
-
1727
1719
if nrows is None :
1728
1720
nrows = self ._nobs
1729
1721
1722
+ # Handle empty file or chunk. If reading incrementally raise
1723
+ # StopIteration. If reading the whole thing return an empty
1724
+ # data frame.
1725
+ if (self ._nobs == 0 ) and nrows == 0 :
1726
+ self ._can_read_value_labels = True
1727
+ self ._data_read = True
1728
+ data = DataFrame (columns = self ._varlist )
1729
+ # Apply dtypes correctly
1730
+ for i , col in enumerate (data .columns ):
1731
+ if self ._dtyplist [i ] is not None :
1732
+ data [col ] = data [col ].astype (self ._dtyplist [i ])
1733
+ if columns is not None :
1734
+ data = self ._do_select_columns (data , columns )
1735
+ return data
1736
+
1730
1737
if (self ._format_version >= 117 ) and (not self ._value_labels_read ):
1731
1738
self ._can_read_value_labels = True
1732
1739
self ._read_strls ()
0 commit comments