Skip to content

Commit 37e026b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tst/ref/test_sql
2 parents 1c3867e + 824a273 commit 37e026b

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

doc/source/whatsnew/v2.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ MultiIndex
314314
I/O
315315
^^^
316316
- Bug in :func:`read_csv` where ``on_bad_lines="warn"`` would write to ``stderr`` instead of raise a Python warning. This now yields a :class:`.errors.ParserWarning` (:issue:`54296`)
317+
- Bug in :func:`read_csv` with ``engine="pyarrow"`` where ``usecols`` wasn't working with a csv with no headers (:issue:`54459`)
317318
- Bug in :func:`read_excel`, with ``engine="xlrd"`` (``xls`` files) erroring when file contains NaNs/Infs (:issue:`54564`)
318319
- Bug in :func:`to_excel`, with ``OdsWriter`` (``ods`` files) writing boolean/string value (:issue:`54994`)
319320

pandas/io/parsers/arrow_parser_wrapper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ def handle_warning(invalid_row):
130130
)
131131
}
132132
self.convert_options["strings_can_be_null"] = "" in self.kwds["null_values"]
133+
# autogenerated column names are prefixed with 'f' in pyarrow.csv
134+
if self.header is None and "include_columns" in self.convert_options:
135+
self.convert_options["include_columns"] = [
136+
f"f{n}" for n in self.convert_options["include_columns"]
137+
]
138+
133139
self.read_options = {
134140
"autogenerate_column_names": self.header is None,
135141
"skip_rows": self.header

pandas/tests/frame/test_arithmetic.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
)
2323
import pandas._testing as tm
2424
from pandas.core.computation import expressions as expr
25-
from pandas.core.computation.expressions import (
26-
_MIN_ELEMENTS,
27-
NUMEXPR_INSTALLED,
28-
)
25+
from pandas.core.computation.expressions import _MIN_ELEMENTS
2926
from pandas.tests.frame.common import (
3027
_check_mixed_float,
3128
_check_mixed_int,
3229
)
30+
from pandas.util.version import Version
3331

3432

3533
@pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"])
@@ -501,10 +499,19 @@ def test_floordiv_axis0(self):
501499
result2 = df.floordiv(ser.values, axis=0)
502500
tm.assert_frame_equal(result2, expected)
503501

504-
@pytest.mark.skipif(not NUMEXPR_INSTALLED, reason="numexpr not installed")
505502
@pytest.mark.parametrize("opname", ["floordiv", "pow"])
506-
def test_floordiv_axis0_numexpr_path(self, opname):
503+
def test_floordiv_axis0_numexpr_path(self, opname, request):
507504
# case that goes through numexpr and has to fall back to masked_arith_op
505+
ne = pytest.importorskip("numexpr")
506+
if (
507+
Version(ne.__version__) >= Version("2.8.7")
508+
and opname == "pow"
509+
and "python" in request.node.callspec.id
510+
):
511+
request.node.add_marker(
512+
pytest.mark.xfail(reason="https://github.com/pydata/numexpr/issues/454")
513+
)
514+
508515
op = getattr(operator, opname)
509516

510517
arr = np.arange(_MIN_ELEMENTS + 100).reshape(_MIN_ELEMENTS // 100 + 1, -1) * 100

pandas/tests/io/parser/test_header.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,21 @@ def test_header_delim_whitespace(all_parsers):
684684
result = parser.read_csv(StringIO(data), delim_whitespace=True)
685685
expected = DataFrame({"a,b": ["1,2", "3,4"]})
686686
tm.assert_frame_equal(result, expected)
687+
688+
689+
def test_usecols_no_header_pyarrow(pyarrow_parser_only):
690+
parser = pyarrow_parser_only
691+
data = """
692+
a,i,x
693+
b,j,y
694+
"""
695+
result = parser.read_csv(
696+
StringIO(data),
697+
header=None,
698+
usecols=[0, 1],
699+
dtype="string[pyarrow]",
700+
dtype_backend="pyarrow",
701+
engine="pyarrow",
702+
)
703+
expected = DataFrame([["a", "i"], ["b", "j"]], dtype="string[pyarrow]")
704+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)