Skip to content

CLN: In DecimalArray implement aliases as properties #26900

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

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 20 additions & 6 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,28 @@ def __init__(self, values, dtype=None, copy=False, context=None):
values = np.asarray(values, dtype=object)

self._data = values
# Some aliases for common attribute names to ensure pandas supports
# these
self._items = self.data = self._data
# those aliases are currently not working due to assumptions
# in internal code (GH-20735)
# self._values = self.values = self.data
self._dtype = DecimalDtype(context)

# aliases for common attribute names, to ensure pandas supports these
@property
def _items(self):
return self._data

@property
def data(self):
return self._data

# those aliases are currently not working due to assumptions
Copy link
Contributor

Choose a reason for hiding this comment

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

don't added commented code unless its germane (its not here)

Copy link
Author

Choose a reason for hiding this comment

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

Which assertion do you mean?

Copy link
Author

Choose a reason for hiding this comment

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

There were 2 commented out attributes. I tuned them into properties with the rest, then commented them out to not delete what the author saw fit to leave in. Not sure what to do here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is fine to keep this in comments.

But for briefness, I think it is enough to have only one property (I would take data) and then you can simply do items = data as alias, and keep the values and _values in a similar way as alias in comments.

# in internal code (GH-20735)
# @property
# def _values(self):
# return self._data

# @property
# def values(self):
# return self._data
# end aliases

@property
def dtype(self):
return self._dtype
Expand Down