Skip to content

Commit c8e22f1

Browse files
authored
TYP: writers.pyi (#40832)
1 parent 36b4990 commit c8e22f1

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

pandas/_libs/writers.pyi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
3+
# TODO: can make this more specific
4+
def write_csv_rows(
5+
data: list,
6+
data_index: np.ndarray,
7+
nlevels: int,
8+
cols: np.ndarray,
9+
writer: object, # _csv.writer
10+
) -> None: ...
11+
12+
def convert_json_to_lines(arr: str) -> str: ...
13+
14+
def max_len_string_array(
15+
arr: np.ndarray, # pandas_string[:]
16+
) -> int: ...
17+
18+
def word_len(val: object) -> int: ...
19+
20+
def string_array_replace_from_nan_rep(
21+
arr: np.ndarray, # np.ndarray[object, ndim=1]
22+
nan_rep: object,
23+
replace: object = ...,
24+
) -> None: ...

pandas/_libs/writers.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def write_csv_rows(
2323
Py_ssize_t nlevels,
2424
ndarray cols,
2525
object writer
26-
):
26+
) -> None:
2727
"""
2828
Write the given data to the writer object, pre-allocating where possible
2929
for performance improvements.
@@ -162,7 +162,7 @@ def string_array_replace_from_nan_rep(
162162
ndarray[object, ndim=1] arr,
163163
object nan_rep,
164164
object replace=np.nan
165-
):
165+
) -> None:
166166
"""
167167
Replace the values in the array with 'replacement' if
168168
they are 'nan_rep'. Return the same array.
@@ -173,5 +173,3 @@ def string_array_replace_from_nan_rep(
173173
for i in range(length):
174174
if arr[i] == nan_rep:
175175
arr[i] = replace
176-
177-
return arr

pandas/io/formats/csvs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,12 @@ def _save_chunk(self, start_i: int, end_i: int) -> None:
308308
data = [res.iget_values(i) for i in range(len(res.items))]
309309

310310
ix = self.data_index[slicer]._format_native_types(**self._number_format)
311-
libwriters.write_csv_rows(data, ix, self.nlevels, self.cols, self.writer)
311+
# error: Argument 4 to "write_csv_rows" has incompatible type
312+
# "Sequence[Hashable]"; expected "ndarray"
313+
libwriters.write_csv_rows(
314+
data,
315+
ix,
316+
self.nlevels,
317+
self.cols, # type: ignore[arg-type]
318+
self.writer,
319+
)

pandas/io/pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5066,7 +5066,7 @@ def _unconvert_string_array(
50665066
if nan_rep is None:
50675067
nan_rep = "nan"
50685068

5069-
data = libwriters.string_array_replace_from_nan_rep(data, nan_rep)
5069+
libwriters.string_array_replace_from_nan_rep(data, nan_rep)
50705070
return data.reshape(shape)
50715071

50725072

0 commit comments

Comments
 (0)