Skip to content

Commit 601d3f3

Browse files
jorisvandenbosschemeeseeksmachine
authored andcommitted
Backport PR pandas-dev#60196: BUG: fix inspect usage when pyarrow or jinja2 is not installed
1 parent a53604d commit 601d3f3

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

doc/source/whatsnew/v2.3.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ Styler
174174

175175
Other
176176
^^^^^
177-
-
177+
- Fixed usage of ``inspect`` when the optional dependencies ``pyarrow`` or ``jinja2``
178+
are not installed (:issue:`60196`)
178179
-
179180

180181
.. ---------------------------------------------------------------------------

pandas/core/arrays/arrow/accessors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _is_valid_pyarrow_dtype(self, pyarrow_dtype) -> bool:
4646

4747
def _validate(self, data):
4848
dtype = data.dtype
49-
if not isinstance(dtype, ArrowDtype):
49+
if pa_version_under10p1 or not isinstance(dtype, ArrowDtype):
5050
# Raise AttributeError so that inspect can handle non-struct Series.
5151
raise AttributeError(self._validation_msg.format(dtype=dtype))
5252

pandas/core/frame.py

+5
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,11 @@ def style(self) -> Styler:
14391439
Please see
14401440
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
14411441
"""
1442+
# Raise AttributeError so that inspect works even if jinja2 is not installed.
1443+
has_jinja2 = import_optional_dependency("jinja2", errors="ignore")
1444+
if not has_jinja2:
1445+
raise AttributeError("The '.style' accessor requires jinja2")
1446+
14421447
from pandas.io.formats.style import Styler
14431448

14441449
return Styler(self)

pandas/tests/frame/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def test_constructor_expanddim(self):
387387

388388
def test_inspect_getmembers(self):
389389
# GH38740
390-
pytest.importorskip("jinja2")
391390
df = DataFrame()
392391
msg = "DataFrame._data is deprecated"
393392
with tm.assert_produces_warning(

pandas/tests/series/test_api.py

-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas._config import using_string_dtype
8-
9-
from pandas.compat import HAS_PYARROW
10-
117
import pandas as pd
128
from pandas import (
139
DataFrame,
@@ -171,12 +167,8 @@ def test_attrs(self):
171167
result = s + 1
172168
assert result.attrs == {"version": 1}
173169

174-
@pytest.mark.xfail(
175-
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
176-
)
177170
def test_inspect_getmembers(self):
178171
# GH38782
179-
pytest.importorskip("jinja2")
180172
ser = Series(dtype=object)
181173
msg = "Series._data is deprecated"
182174
with tm.assert_produces_warning(

0 commit comments

Comments
 (0)