@@ -1139,20 +1139,51 @@ def test_types_regressions() -> None:
11391139
11401140
11411141def test_read_csv () -> None :
1142- if TYPE_CHECKING : # skip pytest
1143- # https://github.com/microsoft/python-type-stubs/issues/87
1144- df11 : pd .DataFrame = pd .read_csv ("foo" )
1145- df12 : pd .DataFrame = pd .read_csv ("foo" , iterator = False )
1146- df13 : pd .DataFrame = pd .read_csv ("foo" , iterator = False , chunksize = None )
1147- df14 : TextFileReader = pd .read_csv ("foo" , chunksize = 0 )
1148- df15 : TextFileReader = pd .read_csv ("foo" , iterator = False , chunksize = 0 )
1149- df16 : TextFileReader = pd .read_csv ("foo" , iterator = True )
1150- df17 : TextFileReader = pd .read_csv ("foo" , iterator = True , chunksize = None )
1151- df18 : TextFileReader = pd .read_csv ("foo" , iterator = True , chunksize = 0 )
1152- df19 : TextFileReader = pd .read_csv ("foo" , chunksize = 0 )
1142+ with ensure_clean () as path :
1143+ Path (path ).write_text ("A,B\n 1,2" )
1144+ check (assert_type (pd .read_csv (path ), pd .DataFrame ), pd .DataFrame )
1145+ check (
1146+ assert_type (pd .read_csv (path , iterator = False ), pd .DataFrame ), pd .DataFrame
1147+ )
1148+ check (
1149+ assert_type (
1150+ pd .read_csv (path , iterator = False , chunksize = None ), pd .DataFrame
1151+ ),
1152+ pd .DataFrame ,
1153+ )
1154+
1155+ with check (
1156+ assert_type (pd .read_csv (path , chunksize = 1 ), TextFileReader ), TextFileReader
1157+ ):
1158+ pass
1159+ with check (
1160+ assert_type (pd .read_csv (path , iterator = False , chunksize = 1 ), TextFileReader ),
1161+ TextFileReader ,
1162+ ):
1163+ pass
1164+ with check (
1165+ assert_type (pd .read_csv (path , iterator = True ), TextFileReader ),
1166+ TextFileReader ,
1167+ ):
1168+ pass
1169+ with check (
1170+ assert_type (
1171+ pd .read_csv (path , iterator = True , chunksize = None ), TextFileReader
1172+ ),
1173+ TextFileReader ,
1174+ ):
1175+ pass
1176+ with check (
1177+ assert_type (pd .read_csv (path , iterator = True , chunksize = 1 ), TextFileReader ),
1178+ TextFileReader ,
1179+ ):
1180+ pass
11531181
11541182 # https://github.com/microsoft/python-type-stubs/issues/118
1155- pd .read_csv ("foo" , storage_options = None )
1183+ check (
1184+ assert_type (pd .read_csv (path , storage_options = None ), pd .DataFrame ),
1185+ pd .DataFrame ,
1186+ )
11561187
11571188
11581189def test_groupby_series_methods () -> None :
@@ -1358,6 +1389,7 @@ def test_set_columns() -> None:
13581389 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [0.0 , 1 , 1 ]})
13591390 # Next line should work, but it is a mypy bug
13601391 # https://github.com/python/mypy/issues/3004
1392+ # pyright doesn't need the ignore
13611393 df .columns = ["c" , "d" ] # type: ignore[assignment]
13621394
13631395
0 commit comments