-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Separate properties module #17590
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
Merged
Merged
Separate properties module #17590
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c9f29d
Separate properties module
jbrockmendel 74bfb1f
remove defunct src/properties.pyx
jbrockmendel dd377af
import cache_readonly and AxisProperty directly from _libs.properties
jbrockmendel 3ad2512
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
from cython cimport Py_ssize_t | ||
|
||
from cpython cimport ( | ||
PyDict_Contains, PyDict_GetItem, PyDict_SetItem) | ||
|
||
|
||
cdef class cache_readonly(object): | ||
|
||
cdef readonly: | ||
object func, name, allow_setting | ||
|
||
def __init__(self, func=None, allow_setting=False): | ||
if func is not None: | ||
self.func = func | ||
self.name = func.__name__ | ||
self.allow_setting = allow_setting | ||
|
||
def __call__(self, func, doc=None): | ||
self.func = func | ||
self.name = func.__name__ | ||
return self | ||
|
||
def __get__(self, obj, typ): | ||
# Get the cache or set a default one if needed | ||
|
||
cache = getattr(obj, '_cache', None) | ||
if cache is None: | ||
try: | ||
cache = obj._cache = {} | ||
except (AttributeError): | ||
return | ||
|
||
if PyDict_Contains(cache, self.name): | ||
# not necessary to Py_INCREF | ||
val = <object> PyDict_GetItem(cache, self.name) | ||
else: | ||
val = self.func(obj) | ||
PyDict_SetItem(cache, self.name, val) | ||
return val | ||
|
||
def __set__(self, obj, value): | ||
|
||
if not self.allow_setting: | ||
raise Exception("cannot set values for [%s]" % self.name) | ||
|
||
# Get the cache or set a default one if needed | ||
cache = getattr(obj, '_cache', None) | ||
if cache is None: | ||
try: | ||
cache = obj._cache = {} | ||
except (AttributeError): | ||
return | ||
|
||
PyDict_SetItem(cache, self.name, value) | ||
|
||
cdef class AxisProperty(object): | ||
cdef: | ||
Py_ssize_t axis | ||
|
||
def __init__(self, axis=0): | ||
self.axis = axis | ||
|
||
def __get__(self, obj, type): | ||
cdef list axes = obj._data.axes | ||
return axes[self.axis] | ||
|
||
def __set__(self, obj, value): | ||
obj._set_axis(self.axis, value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may be able to remove these imports entity and just change where they r called from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It looks like the only direct import of
lib.cache_readonly
is byutil._decorators
, and other imports get it from there. So that would only require changing it in one place. Andlib.AxisProperty
is only used incore.generic
, so also an easy change. Pls confirm before I make this new change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep jose would be good