Skip to content

Csv issue #58348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,10 @@ def setitem_inplace(self, indexer, value) -> None:
# dt64/td64, which do their own validation.
value = np_can_hold_element(arr.dtype, value)

if isinstance(value, np.ndarray) and value.ndim == 1 and len(value) == 1:
# check if the dtype of the block is object
implicit_convert = arr.dtype != 'object'
if (isinstance(value, np.ndarray) and value.ndim == 1 and len(value) == 1
and implicit_convert):
# NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615
value = value[0, ...]

Expand Down
18 changes: 17 additions & 1 deletion pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,19 @@ def read_csv(
) -> DataFrame | TextFileReader: ...


# a helper function for the read_csv(...) below).
# ensures that all keys in dtype are of type str.
# this allows for compatibility with the csv library
def parse_dtype(dtype) -> DtypeArg:
temp = {}
for key in dtype:
if isinstance(key, str):
temp[f"{key}"] = dtype[key]
else:
temp[key] = dtype[key]
return temp


@Appender(
_doc_read_csv_and_table.format(
func_name="read_csv",
Expand Down Expand Up @@ -790,6 +803,9 @@ def read_csv(
storage_options: StorageOptions | None = None,
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
) -> DataFrame | TextFileReader:
# ensures that all keys in dtype are a string for compatibility with csv
dtype = parse_dtype(dtype)

if keep_date_col is not lib.no_default:
# GH#55569
warnings.warn(
Expand Down Expand Up @@ -2026,4 +2042,4 @@ def _validate_skipfooter(kwds: dict[str, Any]) -> None:
if kwds.get("iterator") or kwds.get("chunksize"):
raise ValueError("'skipfooter' not supported for iteration")
if kwds.get("nrows"):
raise ValueError("'skipfooter' not supported with 'nrows'")
raise ValueError("'skipfooter' not supported with 'nrows'")
Loading