@@ -1038,6 +1038,10 @@ def __init__(
1038
1038
self ._order_categoricals = order_categoricals
1039
1039
self ._encoding = ""
1040
1040
self ._chunksize = chunksize
1041
+ if self ._chunksize is not None and (
1042
+ not isinstance (chunksize , int ) or chunksize <= 0
1043
+ ):
1044
+ raise ValueError ("chunksize must be a positive integer when set." )
1041
1045
1042
1046
# State variables for the file
1043
1047
self ._has_string_data = False
@@ -1503,6 +1507,10 @@ def _read_strls(self) -> None:
1503
1507
self .GSO [str (v_o )] = decoded_va
1504
1508
1505
1509
def __next__ (self ) -> DataFrame :
1510
+ if self ._chunksize is None :
1511
+ raise ValueError (
1512
+ "chunksize must be set to a positive integer to use as an iterator."
1513
+ )
1506
1514
return self .read (nrows = self ._chunksize or 1 )
1507
1515
1508
1516
def get_chunk (self , size : Optional [int ] = None ) -> DataFrame :
@@ -1786,7 +1794,7 @@ def _do_convert_categoricals(
1786
1794
vl = value_label_dict [label ]
1787
1795
keys = np .array ([k for k in vl .keys ()])
1788
1796
column = data [col ]
1789
- if column .isin (keys ).all () and self . _chunksize :
1797
+ if self . _chunksize is not None and column .isin (keys ).all ():
1790
1798
# If all categories are in the keys and we are iterating,
1791
1799
# use the same keys for all chunks. If some are missing
1792
1800
# value labels, then we will fall back to the categories
0 commit comments