Skip to content

Commit

Permalink
Merge branch 'main' into freq_string_Y_YE
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Jan 21, 2024
2 parents acec96d + 32c1645 commit 6c31183
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
28 changes: 21 additions & 7 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ValuesView,
)
from enum import Enum
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -1224,12 +1225,12 @@ def module_available(module: str, minversion: str | None = None) -> bool:


def find_stack_level(test_mode=False) -> int:
"""Find the first place in the stack that is not inside xarray.
"""Find the first place in the stack that is not inside xarray or the Python standard library.
This is unless the code emanates from a test, in which case we would prefer
to see the xarray source.
This function is taken from pandas.
This function is taken from pandas and modified to exclude standard library paths.
Parameters
----------
Expand All @@ -1240,19 +1241,32 @@ def find_stack_level(test_mode=False) -> int:
Returns
-------
stacklevel : int
First level in the stack that is not part of xarray.
First level in the stack that is not part of xarray or the Python standard library.
"""
import xarray as xr

pkg_dir = os.path.dirname(xr.__file__)
test_dir = os.path.join(pkg_dir, "tests")
pkg_dir = Path(xr.__file__).parent
test_dir = pkg_dir / "tests"

std_lib_init = sys.modules["os"].__file__
# Mostly to appease mypy; I don't think this can happen...
if std_lib_init is None:
return 0

std_lib_dir = Path(std_lib_init).parent

# https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
frame = inspect.currentframe()
n = 0
while frame:
fname = inspect.getfile(frame)
if fname.startswith(pkg_dir) and (not fname.startswith(test_dir) or test_mode):
if (
fname.startswith(str(pkg_dir))
and (not fname.startswith(str(test_dir)) or test_mode)
) or (
fname.startswith(str(std_lib_dir))
and "site-packages" not in fname
and "dist-packages" not in fname
):
frame = frame.f_back
n += 1
else:
Expand Down
3 changes: 3 additions & 0 deletions xarray/tests/test_cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,9 @@ def test_date_range_errors() -> None:


@requires_cftime
@pytest.mark.xfail(
reason="https://github.com/pydata/xarray/pull/8636#issuecomment-1902775153"
)
@pytest.mark.parametrize(
"start,freq,cal_src,cal_tgt,use_cftime,exp0,exp_pd",
[
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ def test_to_dask_dataframe_coordinates(self):
assert isinstance(actual, dd.DataFrame)
assert_frame_equal(expected.compute(), actual.compute())

@pytest.mark.xfail(
reason="Currently pandas with pyarrow installed will return a `string[pyarrow]` type, "
"which causes the index to have a different type depending on whether pyarrow is installed"
)
def test_to_dask_dataframe_not_daskarray(self):
# Test if DataArray is not a dask array
x = np.random.randn(10)
Expand Down

0 comments on commit 6c31183

Please sign in to comment.