Skip to content

Commit 81ad65d

Browse files
committed
BLD: make all extensions private
closes pandas-dev#12588
1 parent e0647ba commit 81ad65d

File tree

8 files changed

+53
-45
lines changed

8 files changed

+53
-45
lines changed

doc/source/whatsnew/v0.20.0.txt

+16
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,22 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
246246
df.iloc[[0, 2], df.columns.get_loc('A')]
247247

248248

249+
.. _whatsnew_0200.api_breaking.extensions:
250+
251+
Extensions have been made private
252+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
253+
254+
All pandas compiled extensions are now imported privately to the pandas namespace. These are now imported as ``_*`` (:issue:`12588`)
255+
256+
This includes the following c-extensions:
257+
258+
- tslib
259+
- hashtable
260+
- parser
261+
- algos
262+
- lib
263+
- json
264+
249265
.. _whatsnew_0200.api_breaking.index_map:
250266

251267
Map on Index types now return other Index types

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pandas.compat.numpy import *
2424

2525
try:
26-
from pandas import hashtable, tslib, lib
26+
from pandas import hashtable, _tslib, _lib
2727
except ImportError as e: # pragma: no cover
2828
# hack but overkill to use re
2929
module = str(e).lstrip('cannot import name ')

pandas/algos.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ from util cimport numeric, get_nat
4646

4747
cimport lib
4848
from lib cimport is_null_datetimelike
49-
from pandas import lib
49+
from pandas import _lib as lib
5050

5151
cdef int64_t iNaT = get_nat()
5252

pandas/hashtable.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from cpython cimport PyObject, Py_INCREF, PyList_Check, PyTuple_Check
44

55
from khash cimport *
66
from numpy cimport *
7+
from hashtable cimport *
78

89
from libc.stdlib cimport malloc, free
910
from cpython cimport (PyMem_Malloc, PyMem_Realloc, PyMem_Free,
@@ -22,8 +23,6 @@ cdef extern from "numpy/npy_math.h":
2223
cimport cython
2324
cimport numpy as cnp
2425

25-
from pandas.lib import checknull
26-
2726
cnp.import_array()
2827
cnp.import_ufunc()
2928

@@ -41,7 +40,6 @@ cdef extern from "Python.h":
4140

4241
cdef size_t _INIT_VEC_CAP = 128
4342

44-
4543
include "hashtable_class_helper.pxi"
4644
include "hashtable_func_helper.pxi"
4745

pandas/lib.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ from datetime cimport *
5757

5858
from tslib cimport (convert_to_tsobject, convert_to_timedelta64,
5959
_check_all_nulls)
60-
import tslib
61-
from tslib import NaT, Timestamp, Timedelta
60+
from _tslib import NaT, Timestamp, Timedelta
6261

6362
cdef int64_t NPY_NAT = util.get_nat()
6463

pandas/src/period.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ from datetime cimport *
2525
cimport util
2626
cimport lib
2727
from lib cimport is_null_datetimelike, is_period
28-
import lib
29-
from pandas import tslib
28+
import _lib as lib
29+
from pandas import _tslib as tslib
3030
from tslib import Timedelta, Timestamp, iNaT, NaT
3131
from tslib import have_pytz, _get_utcoffset
3232
from tslib cimport (

pandas/tests/api/test_api.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ class TestPDApi(Base, tm.TestCase):
3333
# top-level sub-packages
3434
lib = ['api', 'compat', 'computation', 'core',
3535
'indexes', 'formats', 'pandas',
36-
'test', 'tools', 'tseries',
37-
'types', 'util', 'options', 'io']
38-
39-
# top-level packages that are c-imports, should rename to _*
40-
# to avoid naming conflicts
41-
lib_to_rename = ['algos', 'hashtable', 'tslib', 'msgpack', 'sparse',
42-
'json', 'lib', 'index', 'parser']
36+
'test', 'tools', 'tseries', 'msgpack',
37+
'types', 'util', 'options', 'sparse', 'io']
4338

4439
# these are already deprecated; awaiting removal
4540
deprecated_modules = ['stats', 'datetools']

setup.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ def is_platform_mac():
113113
_pxi_dep_template = {
114114
'algos': ['algos_common_helper.pxi.in', 'algos_groupby_helper.pxi.in',
115115
'algos_take_helper.pxi.in', 'algos_rank_helper.pxi.in'],
116-
'_join': ['join_helper.pxi.in', 'joins_func_helper.pxi.in'],
116+
'join': ['join_helper.pxi.in', 'joins_func_helper.pxi.in'],
117117
'hashtable': ['hashtable_class_helper.pxi.in',
118118
'hashtable_func_helper.pxi.in'],
119119
'index': ['index_class_helper.pxi.in'],
120-
'_sparse': ['sparse_op_helper.pxi.in']
120+
'sparse': ['sparse_op_helper.pxi.in']
121121
}
122122
_pxifiles = []
123123
_pxi_dep = {}
@@ -471,54 +471,54 @@ def pxd(name):
471471
libraries = ['m'] if not is_platform_windows() else []
472472

473473
ext_data = dict(
474-
lib={'pyxfile': 'lib',
475-
'pxdfiles': [],
476-
'depends': lib_depends},
474+
_lib={'pyxfile': 'lib',
475+
'pxdfiles': [],
476+
'depends': lib_depends},
477477
hashtable={'pyxfile': 'hashtable',
478-
'pxdfiles': ['hashtable'],
478+
'pxdfiles': ['hashtable', 'src/util', 'src/khash'],
479479
'depends': (['pandas/src/klib/khash_python.h']
480480
+ _pxi_dep['hashtable'])},
481-
tslib={'pyxfile': 'tslib',
482-
'depends': tseries_depends,
483-
'sources': ['pandas/src/datetime/np_datetime.c',
484-
'pandas/src/datetime/np_datetime_strings.c',
485-
'pandas/src/period_helper.c']},
481+
_tslib={'pyxfile': 'tslib',
482+
'depends': tseries_depends,
483+
'sources': ['pandas/src/datetime/np_datetime.c',
484+
'pandas/src/datetime/np_datetime_strings.c',
485+
'pandas/src/period_helper.c']},
486486
_period={'pyxfile': 'src/period',
487487
'depends': tseries_depends,
488488
'sources': ['pandas/src/datetime/np_datetime.c',
489489
'pandas/src/datetime/np_datetime_strings.c',
490490
'pandas/src/period_helper.c']},
491-
index={'pyxfile': 'index',
492-
'sources': ['pandas/src/datetime/np_datetime.c',
493-
'pandas/src/datetime/np_datetime_strings.c'],
494-
'pxdfiles': ['src/util', 'hashtable'],
495-
'depends': _pxi_dep['index']},
496-
algos={'pyxfile': 'algos',
497-
'pxdfiles': ['src/util', 'hashtable'],
498-
'depends': _pxi_dep['algos']},
491+
_index={'pyxfile': 'index',
492+
'sources': ['pandas/src/datetime/np_datetime.c',
493+
'pandas/src/datetime/np_datetime_strings.c'],
494+
'pxdfiles': ['src/util', 'hashtable'],
495+
'depends': _pxi_dep['index']},
496+
_algos={'pyxfile': 'algos',
497+
'pxdfiles': ['src/util', 'hashtable'],
498+
'depends': _pxi_dep['algos']},
499499
_join={'pyxfile': 'src/join',
500500
'pxdfiles': ['src/util', 'hashtable'],
501-
'depends': _pxi_dep['_join']},
501+
'depends': _pxi_dep['join']},
502502
_window={'pyxfile': 'window',
503503
'pxdfiles': ['src/skiplist', 'src/util'],
504504
'depends': ['pandas/src/skiplist.pyx',
505505
'pandas/src/skiplist.h']},
506-
parser={'pyxfile': 'parser',
507-
'depends': ['pandas/src/parser/tokenizer.h',
508-
'pandas/src/parser/io.h',
509-
'pandas/src/numpy_helper.h'],
510-
'sources': ['pandas/src/parser/tokenizer.c',
511-
'pandas/src/parser/io.c']},
506+
_parser={'pyxfile': 'parser',
507+
'depends': ['pandas/src/parser/tokenizer.h',
508+
'pandas/src/parser/io.h',
509+
'pandas/src/numpy_helper.h'],
510+
'sources': ['pandas/src/parser/tokenizer.c',
511+
'pandas/src/parser/io.c']},
512512
_sparse={'pyxfile': 'src/sparse',
513513
'depends': ([srcpath('sparse', suffix='.pyx')] +
514-
_pxi_dep['_sparse'])},
514+
_pxi_dep['sparse'])},
515515
_testing={'pyxfile': 'src/testing',
516516
'depends': [srcpath('testing', suffix='.pyx')]},
517517
_hash={'pyxfile': 'src/hash',
518518
'depends': [srcpath('hash', suffix='.pyx')]},
519519
)
520520

521-
ext_data["io.sas.saslib"] = {'pyxfile': 'io/sas/saslib'}
521+
ext_data["io.sas._saslib"] = {'pyxfile': 'io/sas/saslib'}
522522

523523
extensions = []
524524

@@ -583,7 +583,7 @@ def pxd(name):
583583
root, _ = os.path.splitext(ext.sources[0])
584584
ext.sources[0] = root + suffix
585585

586-
ujson_ext = Extension('pandas.json',
586+
ujson_ext = Extension('pandas._json',
587587
depends=['pandas/src/ujson/lib/ultrajson.h',
588588
'pandas/src/datetime_helper.h',
589589
'pandas/src/numpy_helper.h'],

0 commit comments

Comments
 (0)