Skip to content

Commit 9d68f91

Browse files
committed
change warnings behavior
1 parent 74f01a7 commit 9d68f91

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

pandas/io/parsers/arrow_parser_wrapper.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pandas._libs import lib
77
from pandas.compat._optional import import_optional_dependency
88
from pandas.errors import (
9-
DtypeWarning,
109
Pandas4Warning,
1110
ParserError,
1211
ParserWarning,
@@ -146,27 +145,26 @@ def handle_warning(invalid_row) -> str:
146145
if isinstance(self.dtype, dict):
147146
column_types = {}
148147
for col, col_dtype in self.dtype.items():
148+
# TODO: Category dtypes are not currently handled - may cause issues
149+
# with categorical data preservation in pyarrow engine
150+
if col_dtype == "category":
151+
continue
152+
149153
try:
150154
numpy_dtype = pandas_dtype(col_dtype).type
151155
pyarrow_dtype = pa.from_numpy_dtype(numpy_dtype)
152156
column_types[col] = pyarrow_dtype
153157
except (TypeError, ValueError, pa.ArrowNotImplementedError):
154-
warnings.warn(
155-
f"Column '{col}' has dtype '{col_dtype}', "
156-
"which may not be handled correctly by the pyarrow engine.",
157-
DtypeWarning,
158-
stacklevel=find_stack_level(),
159-
)
158+
# TODO: Unsupported dtypes silently ignored - may cause unexpected
159+
# behavior when pyarrow applies default inference instead of user's dtype
160+
continue
160161

161162
if column_types:
162163
self.convert_options["column_types"] = column_types
163164
else:
164-
warnings.warn(
165-
f"Global dtype '{self.dtype}' not supported with pyarrow engine. "
166-
"Use dtype dictionary instead.",
167-
DtypeWarning,
168-
stacklevel=find_stack_level(),
169-
)
165+
# TODO: Global dtypes not supported - may cause inconsistent behavior
166+
# between engines, especially for leading zero preservation
167+
pass
170168

171169
self.read_options = {
172170
"autogenerate_column_names": self.header is None,

pandas/tests/io/parser/test_preserve_leading_zeros.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import pytest
44

5-
from pandas.errors import DtypeWarning
6-
7-
import pandas._testing as tm
8-
95

106
def test_leading_zeros_preserved_with_dtype_str(all_parsers, request):
117
# GH#57666: pyarrow engine strips leading zeros when dtype=str is passed
@@ -20,19 +16,10 @@ def test_leading_zeros_preserved_with_dtype_str(all_parsers, request):
2016
EF,000023607,ghi,0205
2117
GH,100102040,jkl,0205"""
2218

23-
if engine_name == "pyarrow":
24-
with tm.assert_produces_warning(
25-
DtypeWarning, match="not supported with pyarrow engine"
26-
):
27-
result = parser.read_csv(
28-
StringIO(data),
29-
dtype=str,
30-
)
31-
else:
32-
result = parser.read_csv(
33-
StringIO(data),
34-
dtype=str,
35-
)
19+
result = parser.read_csv(
20+
StringIO(data),
21+
dtype=str,
22+
)
3623

3724
try:
3825
assert result.shape == (4, 4)

0 commit comments

Comments
 (0)