Skip to content
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

DOC: rm np import #4949

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Changes from 1 commit
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
1 change: 1 addition & 0 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ def where(self, cond, other=dtypes.NA, drop: bool = False):

Examples
--------
>>> import xarray as xr
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had thought we didn't do this by convention (neither for numpy, which is in the line below, contradicting that convention), because it would be everywhere.

Is that the case? I don't have a particularly strong view either way, though we could decide on the convention now.

Copy link
Collaborator

@keewis keewis Feb 24, 2021

Choose a reason for hiding this comment

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

that's what I was thinking, too: technically we don't need any imports of numpy, pandas or xarray:

xarray/conftest.py

Lines 26 to 41 in 351b0aa

@pytest.fixture(autouse=True)
def add_standard_imports(doctest_namespace, tmpdir):
import numpy as np
import pandas as pd
import xarray as xr
doctest_namespace["np"] = np
doctest_namespace["pd"] = pd
doctest_namespace["xr"] = xr
# always seed numpy.random to make the examples deterministic
np.random.seed(0)
# always switch to the temporary directory, so files get written there
tmpdir.chdir()
so I would lean towards removing all of those. That said, it would probably be good to have some obvious part of the docs (api.rst?) explain that all examples assume these imports.

>>> import numpy as np
>>> a = xr.DataArray(np.arange(25).reshape(5, 5), dims=("x", "y"))
>>> a
Expand Down