Skip to content

Commit ce2c6b5

Browse files
author
Antoine Pitrou
committed
Use a dedicated indexing.pyx module in pandas._libs
1 parent 9600371 commit ce2c6b5

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

pandas/_libs/indexing.pyx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# cython: profile=False
2+
3+
cdef class _NDFrameIndexerBase:
4+
'''
5+
A base class for _NDFrameIndexer for fast instantiation and attribute
6+
access.
7+
'''
8+
cdef public object obj, name, _ndim
9+
10+
def __init__(self, name, obj):
11+
self.obj = obj
12+
self.name = name
13+
self._ndim = None
14+
15+
@property
16+
def ndim(self):
17+
# Delay `ndim` instantiation until required as reading it
18+
# from `obj` isn't entirely cheap.
19+
ndim = self._ndim
20+
if ndim is None:
21+
ndim = self._ndim = self.obj.ndim
22+
return ndim

pandas/_libs/lib.pyx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,27 +1839,5 @@ cdef class BlockPlacement:
18391839
return self._as_slice
18401840

18411841

1842-
cdef class _NDFrameIndexerBase:
1843-
'''
1844-
A base class for _NDFrameIndexer for fast instantiation and attribute
1845-
access.
1846-
'''
1847-
cdef public object obj, name, _ndim
1848-
1849-
def __init__(self, name, obj):
1850-
self.obj = obj
1851-
self.name = name
1852-
self._ndim = None
1853-
1854-
@property
1855-
def ndim(self):
1856-
# Delay `ndim` instantiation until required as reading it
1857-
# from `obj` isn't entirely cheap.
1858-
ndim = self._ndim
1859-
if ndim is None:
1860-
ndim = self._ndim = self.obj.ndim
1861-
return ndim
1862-
1863-
18641842
include "reduce.pyx"
18651843
include "inference.pyx"

pandas/core/generic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=W0231,E1101
22
import collections
3+
import functools
34
import warnings
45
import operator
56
import weakref
@@ -1841,10 +1842,8 @@ def to_latex(self, buf=None, columns=None, col_space=None, header=True,
18411842
@classmethod
18421843
def _create_indexer(cls, name, indexer):
18431844
"""Create an indexer like _name in the class."""
1844-
from functools import partial
1845-
18461845
if getattr(cls, name, None) is None:
1847-
_indexer = partial(indexer, name)
1846+
_indexer = functools.partial(indexer, name)
18481847
setattr(cls, name, property(_indexer, doc=indexer.__doc__))
18491848

18501849
def get(self, key, default=None):

pandas/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pandas.core.common import (is_bool_indexer, _asarray_tuplesafe,
2424
is_null_slice, is_full_slice,
2525
_values_from_object)
26-
from pandas._libs.lib import _NDFrameIndexerBase
26+
from pandas._libs.indexing import _NDFrameIndexerBase
2727

2828

2929
# the supported indexers

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class CheckSDist(sdist_class):
335335
'pandas/_libs/index.pyx',
336336
'pandas/_libs/algos.pyx',
337337
'pandas/_libs/join.pyx',
338+
'pandas/_libs/indexing.pyx',
338339
'pandas/_libs/interval.pyx',
339340
'pandas/_libs/hashing.pyx',
340341
'pandas/_libs/testing.pyx',
@@ -519,6 +520,7 @@ def pxd(name):
519520
'depends': _pxi_dep['join']},
520521
'_libs.reshape': {'pyxfile': '_libs/reshape',
521522
'depends': _pxi_dep['reshape']},
523+
'_libs.indexing': {'pyxfile': '_libs/indexing'},
522524
'_libs.interval': {'pyxfile': '_libs/interval',
523525
'pxdfiles': ['_libs/hashtable'],
524526
'depends': _pxi_dep['interval']},

0 commit comments

Comments
 (0)