Skip to content

Commit

Permalink
Update for arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Jan 7, 2024
1 parent 88cfd0c commit 1f8e6ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 13 additions & 7 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
unique,
value_counts_internal as value_counts,
)
from pandas.core.arrays import ArrowExtensionArray
from pandas.core.arrays.base import (
ExtensionArray,
_extension_array_shared_docs,
Expand Down Expand Up @@ -369,13 +370,18 @@ def _ensure_simple_new_inputs(
right = ensure_wrapped_if_datetimelike(right)
right = extract_array(right, extract_numpy=True)

lbase = getattr(left, "_ndarray", left)
lbase = getattr(lbase, "_data", lbase).base
rbase = getattr(right, "_ndarray", right)
rbase = getattr(rbase, "_data", rbase).base
if lbase is not None and lbase is rbase:
# If these share data, then setitem could corrupt our IA
right = right.copy()
if isinstance(left, ArrowExtensionArray) or isinstance(
right, ArrowExtensionArray
):
pass
else:
lbase = getattr(left, "_ndarray", left)
lbase = getattr(lbase, "_data", lbase).base
rbase = getattr(right, "_ndarray", right)
rbase = getattr(rbase, "_data", rbase).base
if lbase is not None and lbase is rbase:
# If these share data, then setitem could corrupt our IA
right = right.copy()

dtype = IntervalDtype(left.dtype, closed=closed)

Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/indexes/interval/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_unsigned_integer_dtype
from pandas.core.dtypes.dtypes import IntervalDtype

Expand Down Expand Up @@ -510,10 +512,14 @@ def test_dtype_closed_mismatch():
IntervalArray([], dtype=dtype, closed="neither")


def test_masked_dtype():
@pytest.mark.parametrize(
"dtype",
["Float64", pytest.param("float64[pyarrow]", marks=td.skip_if_no("pyarrow"))],
)
def test_ea_dtype(dtype):
# GH#56765
bins = [(0.0, 0.4), (0.4, 0.6)]
interval_dtype = IntervalDtype(subtype="Float64", closed="left")
interval_dtype = IntervalDtype(subtype=dtype, closed="left")
result = IntervalIndex.from_tuples(bins, closed="left", dtype=interval_dtype)
assert result.dtype == interval_dtype
expected = IntervalIndex.from_tuples(bins, closed="left").astype(interval_dtype)
Expand Down

0 comments on commit 1f8e6ff

Please sign in to comment.