Skip to content

DEPS: Add warning if pyarrow is not installed #56896

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

Merged
merged 14 commits into from
Jan 19, 2024
25 changes: 23 additions & 2 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,29 @@
FutureWarning,
stacklevel=2,
)
# Don't allow users to use pandas.os or pandas.warnings
del os, warnings
# Don't allow users to use pandas.os
del os
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not run this this at the end with the other modules? Seems like it's easier to maintain if there is all the clean up at the end or next to the import, but no big deal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really.

Personally I like to keep the del closed to where it's being used, but no strong preference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think os is not being used in the code before beibg closed. As said, not important, but to me personally it makes sense to open and close around the block where it is being used, or open and close at the beginning and the end if it's an import that is used in several places. Now os is being opened at the beginning, and closed in the middle, in a kind of random place if I'm not wrong. No huge difference, but I think it'll help maintain the code if closed at the end (or we move the import and del around where it is being used).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the os delete with the deletion of warnings/pa_version_under10p1.


# DeprecationWarning for missing pyarrow
from pandas.compat.pyarrow import pa_version_under10p1

if pa_version_under10p1:
import warnings
from pandas.compat._optional import VERSIONS

warnings.warn(
f"""
Pyarrow will become a future required dependency of pandas,
but was not found to be installed on your system.
(or was too old - pyarrow {VERSIONS['pyarrow']}
is the current minimum supported version as of this release)
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466
""",
DeprecationWarning,
stacklevel=2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make this stacklevel=1?

Because this code is top-level and not inside a function or method, it one less than the typical stacklevel of 2 we use in a direct function/method.
Setting it as 1 would avoid that it triggers a warning when you call a function that has an inline import pandas (not sure how important this is, though)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning doesn't pop up in the REPL when I import pandas if I do stacklevel=1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK forget this. I did test it, but should have done something wrong because now I can't reproduce getting the warning with plain import and stacklevel 1

)
del pa_version_under10p1, warnings

# module level doc-string
__doc__ = """
Expand Down