Skip to content

Commit

Permalink
Revert "Add custom name setter and getter for proxy objects in `cudf.…
Browse files Browse the repository at this point in the history
…pandas` …"

This reverts commit 2b2058d.
  • Loading branch information
galipremsagar authored Jul 12, 2024
1 parent dddeb12 commit c6442c9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 87 deletions.
50 changes: 3 additions & 47 deletions python/cudf/cudf/pandas/_wrappers/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,6 @@ def Index__new__(cls, *args, **kwargs):
return self


def name(self):
return self._fsproxy_wrapped._name


def Index__setattr__(self, name, value):
if name.startswith("_"):
object.__setattr__(self, name, value)
return
if name == "name":
setattr(self._fsproxy_wrapped, "_name", value)
if name == "names":
setattr(self._fsproxy_wrapped, "_names", value)
return _FastSlowAttribute("__setattr__").__get__(self, type(self))(
name, value
)


Index = make_final_proxy_type(
"Index",
cudf.Index,
Expand All @@ -294,13 +277,11 @@ def Index__setattr__(self, name, value):
"__iter__": custom_iter,
"__init__": _DELETE,
"__new__": Index__new__,
"__setattr__": Index__setattr__,
"_constructor": _FastSlowAttribute("_constructor"),
"__array_ufunc__": _FastSlowAttribute("__array_ufunc__"),
"_accessors": set(),
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"name": property(name),
},
)

Expand All @@ -311,11 +292,7 @@ def Index__setattr__(self, name, value):
fast_to_slow=lambda fast: fast.to_pandas(),
slow_to_fast=cudf.from_pandas,
bases=(Index,),
additional_attributes={
"__init__": _DELETE,
"__setattr__": Index__setattr__,
"name": property(name),
},
additional_attributes={"__init__": _DELETE},
)

SparseDtype = make_final_proxy_type(
Expand All @@ -342,11 +319,7 @@ def Index__setattr__(self, name, value):
fast_to_slow=lambda fast: fast.to_pandas(),
slow_to_fast=cudf.from_pandas,
bases=(Index,),
additional_attributes={
"__init__": _DELETE,
"__setattr__": Index__setattr__,
"name": property(name),
},
additional_attributes={"__init__": _DELETE},
)

Categorical = make_final_proxy_type(
Expand Down Expand Up @@ -377,8 +350,6 @@ def Index__setattr__(self, name, value):
"__init__": _DELETE,
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"__setattr__": Index__setattr__,
"name": property(name),
},
)

Expand Down Expand Up @@ -414,8 +385,6 @@ def Index__setattr__(self, name, value):
"__init__": _DELETE,
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"__setattr__": Index__setattr__,
"name": property(name),
},
)

Expand Down Expand Up @@ -472,8 +441,6 @@ def Index__setattr__(self, name, value):
"__init__": _DELETE,
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"__setattr__": Index__setattr__,
"name": property(name),
},
)

Expand Down Expand Up @@ -507,23 +474,14 @@ def Index__setattr__(self, name, value):
additional_attributes={"__hash__": _FastSlowAttribute("__hash__")},
)


def names(self):
return self._fsproxy_wrapped._names


MultiIndex = make_final_proxy_type(
"MultiIndex",
cudf.MultiIndex,
pd.MultiIndex,
fast_to_slow=lambda fast: fast.to_pandas(),
slow_to_fast=cudf.from_pandas,
bases=(Index,),
additional_attributes={
"__init__": _DELETE,
"__setattr__": Index__setattr__,
"name": property(names),
},
additional_attributes={"__init__": _DELETE},
)

TimeGrouper = make_intermediate_proxy_type(
Expand Down Expand Up @@ -711,8 +669,6 @@ def names(self):
"__init__": _DELETE,
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"__setattr__": Index__setattr__,
"name": property(name),
},
)

Expand Down
40 changes: 0 additions & 40 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,43 +1592,3 @@ def test_at_setitem_empty():
df.at[0, "new"] = 2.0
expected = pd.DataFrame({"name": [1.0], "new": [2.0]})
tm.assert_frame_equal(df, expected)


@pytest.mark.parametrize(
"index",
[
xpd.Index([1, 2, 3], name="foo"),
xpd.Index(["a", "b", "c"], name="foo"),
xpd.RangeIndex(start=0, stop=3, step=1, name="foo"),
xpd.CategoricalIndex(["a", "b", "a"], name="foo"),
xpd.DatetimeIndex(
["2024-04-24", "2025-04-24", "2026-04-24"], name="foo"
),
xpd.TimedeltaIndex(["1 days", "2 days", "3 days"], name="foo"),
xpd.PeriodIndex(
["2024-06", "2023-06", "2022-06"], freq="M", name="foo"
),
xpd.IntervalIndex.from_breaks([0, 1, 2, 3], name="foo"),
xpd.MultiIndex.from_tuples(
[(1, "a"), (2, "b"), (3, "c")], names=["foo1", "bar1"]
),
],
)
def test_change_index_name(index):
s = xpd.Series([1, 2, object()], index=index)
df = xpd.DataFrame({"values": [1, 2, object()]}, index=index)

if isinstance(index, xpd.MultiIndex):
names = ["foo2", "bar2"]
s.index.names = names
df.index.names = names

assert s.index.names == names
assert df.index.names == names
else:
name = "bar"
s.index.name = name
df.index.name = name

assert s.index.name == name
assert df.index.name == name

0 comments on commit c6442c9

Please sign in to comment.