Skip to content

Commit f9dcad7

Browse files
committed
BLD: rename / move some extensions
xref pandas-dev#12588 pandas.parser -> io/libparsers.pyx pandas.json -> pandas.io.json.libjson pandas.io.sas.saslib -> libsas pandas.msgpack -> pandas.io.msgpack
1 parent dd368eb commit f9dcad7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+213
-140
lines changed

asv_bench/benchmarks/binary_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ def setup(self):
107107
self.s = Series(date_range('20010101', periods=self.N, freq='T', tz='US/Eastern'))
108108
self.ts = self.s[self.halfway]
109109

110-
self.s2 = Series(date_range('20010101', periods=self.N, freq='s', tz='US/Eastern'))
110+
self.s2 = Series(date_range('20010101', periods=self.N, freq='s', tz='US/Eastern'))

asv_bench/benchmarks/panel_methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def time_shift(self):
2121
self.panel.shift(1)
2222

2323
def time_shift_minor(self):
24-
self.panel.shift(1, axis='minor')
24+
self.panel.shift(1, axis='minor')

doc/source/whatsnew/v0.20.0.txt

+18
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,24 @@ New Behavior:
446446
In [11]: index.memory_usage(deep=True)
447447
Out[11]: 260
448448

449+
.. _whatsnew_0200.api_breaking.extensions:
450+
451+
Extension Modules Moving
452+
^^^^^^^^^^^^^^^^^^^^^^^^
453+
454+
Some formerly public extension modules have been moved and/or renamed. These are all removed from the public API.
455+
If indicated, a deprecation warning will be issued if you reference that module. (:issue:`12588`)
456+
457+
.. csv-table::
458+
:header: "Previous Location", "New Location", "Deprecated"
459+
:widths: 30, 30, 4
460+
461+
"pandas.json", "pandas.io.json.libjson", "X"
462+
"pandas.parser", "pandas.io.libparsers", "X"
463+
"pandas.io.sas.saslib", "pandas.io.sas.libsas", ""
464+
"pandas.msgpack", "pandas.io.msgpack", ""
465+
466+
449467
.. _whatsnew_0200.api_breaking.groupby_describe:
450468

451469
Groupby Describe Formatting

pandas/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@
5353
from pandas.tools.util import to_numeric
5454
from pandas.core.reshape import melt
5555
from pandas.util.print_versions import show_versions
56-
5756
from pandas.io.api import *
58-
5957
from pandas.util._tester import test
6058

59+
# extension module deprecations
60+
from pandas.util.depr_module import _DeprecatedModule
61+
62+
json = _DeprecatedModule(deprmod='pandas.json', deprmodto='pandas.io.json.libjson')
63+
parser = _DeprecatedModule(deprmod='pandas.parser', deprmodto='pandas.io.libparsers')
64+
6165
# use the closest tagged version if possible
6266
from ._version import get_versions
6367
v = get_versions()

pandas/io/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pandas.io.json import read_json
1212
from pandas.io.html import read_html
1313
from pandas.io.sql import read_sql, read_sql_table, read_sql_query
14-
from pandas.io.sas.sasreader import read_sas
14+
from pandas.io.sas import read_sas
1515
from pandas.io.feather_format import read_feather
1616
from pandas.io.stata import read_stata
1717
from pandas.io.pickle import read_pickle, to_pickle

pandas/io/excel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
EmptyDataError, get_filepath_or_buffer,
2020
_NA_VALUES)
2121
from pandas.tseries.period import Period
22-
from pandas import json
22+
from pandas.io.json import libjson
2323
from pandas.compat import (map, zip, reduce, range, lrange, u, add_metaclass,
2424
string_types, OrderedDict)
2525
from pandas.core import config
@@ -1434,7 +1434,7 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0,
14341434
elif isinstance(cell.val, date):
14351435
num_format_str = self.date_format
14361436

1437-
stylekey = json.dumps(cell.style)
1437+
stylekey = libjson.dumps(cell.style)
14381438
if num_format_str:
14391439
stylekey += num_format_str
14401440

@@ -1562,7 +1562,7 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0,
15621562
elif isinstance(cell.val, date):
15631563
num_format_str = self.date_format
15641564

1565-
stylekey = json.dumps(cell.style)
1565+
stylekey = libjson.dumps(cell.style)
15661566
if num_format_str:
15671567
stylekey += num_format_str
15681568

pandas/io/json/json.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import numpy as np
55

6-
import pandas.json as _json
6+
from pandas.io.json import libjson
77
from pandas.tslib import iNaT
88
from pandas.compat import StringIO, long, u
99
from pandas import compat, isnull
@@ -13,8 +13,8 @@
1313
from pandas.formats.printing import pprint_thing
1414
from .normalize import _convert_to_line_delimits
1515

16-
loads = _json.loads
17-
dumps = _json.dumps
16+
loads = libjson.loads
17+
dumps = libjson.dumps
1818

1919

2020
# interface to/from

pandas/msgpack/__init__.py renamed to pandas/io/msgpack/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from collections import namedtuple
44

5-
from pandas.msgpack.exceptions import * # noqa
6-
from pandas.msgpack._version import version # noqa
5+
from pandas.io.msgpack.exceptions import * # noqa
6+
from pandas.io.msgpack._version import version # noqa
77

88

99
class ExtType(namedtuple('ExtType', 'code data')):
@@ -19,8 +19,8 @@ def __new__(cls, code, data):
1919

2020
import os # noqa
2121

22-
from pandas.msgpack._packer import Packer # noqa
23-
from pandas.msgpack._unpacker import unpack, unpackb, Unpacker # noqa
22+
from pandas.io.msgpack._packer import Packer # noqa
23+
from pandas.io.msgpack._unpacker import unpack, unpackb, Unpacker # noqa
2424

2525

2626
def pack(o, stream, **kwargs):

pandas/msgpack/_packer.pyx renamed to pandas/io/msgpack/_packer.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ from libc.stdlib cimport *
66
from libc.string cimport *
77
from libc.limits cimport *
88

9-
from pandas.msgpack.exceptions import PackValueError
10-
from pandas.msgpack import ExtType
9+
from pandas.io.msgpack.exceptions import PackValueError
10+
from pandas.io.msgpack import ExtType
1111

1212

13-
cdef extern from "../src/msgpack/pack.h":
13+
cdef extern from "../../src/msgpack/pack.h":
1414
struct msgpack_packer:
1515
char* buf
1616
size_t length

pandas/msgpack/_unpacker.pyx renamed to pandas/io/msgpack/_unpacker.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ from libc.stdlib cimport *
1111
from libc.string cimport *
1212
from libc.limits cimport *
1313

14-
from pandas.msgpack.exceptions import (BufferFull, OutOfData,
15-
UnpackValueError, ExtraData)
16-
from pandas.msgpack import ExtType
14+
from pandas.io.msgpack.exceptions import (BufferFull, OutOfData,
15+
UnpackValueError, ExtraData)
16+
from pandas.io.msgpack import ExtType
1717

1818

19-
cdef extern from "../src/msgpack/unpack.h":
19+
cdef extern from "../../src/msgpack/unpack.h":
2020
ctypedef struct msgpack_user:
2121
bint use_list
2222
PyObject* object_hook
File renamed without changes.
File renamed without changes.

pandas/io/packers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
from pandas.core.internals import BlockManager, make_block, _safe_reshape
6565
import pandas.core.internals as internals
6666

67-
from pandas.msgpack import Unpacker as _Unpacker, Packer as _Packer, ExtType
67+
from pandas.io.msgpack import Unpacker as _Unpacker, Packer as _Packer, ExtType
6868
from pandas.util._move import (
6969
BadMove as _BadMove,
7070
move_into_mutable_buffer as _move_into_mutable_buffer,

pandas/io/parsers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from pandas.util.decorators import Appender
3838

3939
import pandas.lib as lib
40-
import pandas.parser as _parser
40+
import pandas.io.libparsers as libparsers
4141

4242

4343
# BOM character (byte order mark)
@@ -1415,7 +1415,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
14151415

14161416
if issubclass(cvals.dtype.type, np.integer) and self.compact_ints:
14171417
cvals = lib.downcast_int64(
1418-
cvals, _parser.na_values,
1418+
cvals, libparsers.na_values,
14191419
self.use_unsigned)
14201420

14211421
result[c] = cvals
@@ -1533,7 +1533,7 @@ def __init__(self, src, **kwds):
15331533
# #2442
15341534
kwds['allow_leading_cols'] = self.index_col is not False
15351535

1536-
self._reader = _parser.TextReader(src, **kwds)
1536+
self._reader = libparsers.TextReader(src, **kwds)
15371537

15381538
# XXX
15391539
self.usecols, self.usecols_dtype = _validate_usecols_arg(

pandas/parser.pyx renamed to pandas/io/parsers.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ from cpython cimport (PyObject, PyBytes_FromString,
1313
PyUnicode_Check, PyUnicode_AsUTF8String,
1414
PyErr_Occurred, PyErr_Fetch)
1515
from cpython.ref cimport PyObject, Py_XDECREF
16-
from io.common import ParserError, DtypeWarning, EmptyDataError, ParserWarning
16+
from pandas.io.common import (ParserError, DtypeWarning,
17+
EmptyDataError, ParserWarning)
1718

1819
# Import CParserError as alias of ParserError for backwards compatibility.
1920
# Ultimately, we want to remove this import. See gh-12665 and gh-14479.
20-
from io.common import CParserError
21+
from pandas.io.common import CParserError
2122

2223
cdef extern from "Python.h":
2324
object PyUnicode_FromString(char *v)

pandas/io/sas/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .sasreader import read_sas # noqa
File renamed without changes.

pandas/io/sas/sas7bdat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import numpy as np
2121
import struct
2222
import pandas.io.sas.sas_constants as const
23-
from pandas.io.sas.saslib import Parser
23+
from pandas.io.sas.libsas import Parser
2424

2525

2626
class _subheader_pointer(object):

pandas/json.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# flake8: noqa
2+
3+
import warnings
4+
warnings.warn("The pandas.json module is deprecated and will be "
5+
"removed in a future version. Please import from "
6+
"the pandas.io.json instead", FutureWarning, stacklevel=2)
7+
from pandas.io.json.libjson import dumps, loads

pandas/parser.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# flake8: noqa
2+
3+
import warnings
4+
warnings.warn("The pandas.parser module is deprecated and will be "
5+
"removed in a future version. Please import from "
6+
"the pandas.io.parser instead", FutureWarning, stacklevel=2)
7+
from pandas.io.libparsers import na_values
8+
from pandas.io.common import CParserError

pandas/src/ujson/python/ujson.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static PyMethodDef ujsonMethods[] = {
8080

8181
static struct PyModuleDef moduledef = {
8282
PyModuleDef_HEAD_INIT,
83-
"_pandasujson",
83+
"_libjson",
8484
0, /* m_doc */
8585
-1, /* m_size */
8686
ujsonMethods, /* m_methods */
@@ -90,14 +90,14 @@ static struct PyModuleDef moduledef = {
9090
NULL /* m_free */
9191
};
9292

93-
#define PYMODINITFUNC PyMODINIT_FUNC PyInit_json(void)
93+
#define PYMODINITFUNC PyMODINIT_FUNC PyInit_libjson(void)
9494
#define PYMODULE_CREATE() PyModule_Create(&moduledef)
9595
#define MODINITERROR return NULL
9696

9797
#else
9898

99-
#define PYMODINITFUNC PyMODINIT_FUNC initjson(void)
100-
#define PYMODULE_CREATE() Py_InitModule("json", ujsonMethods)
99+
#define PYMODINITFUNC PyMODINIT_FUNC initlibjson(void)
100+
#define PYMODULE_CREATE() Py_InitModule("libjson", ujsonMethods)
101101
#define MODINITERROR return
102102

103103
#endif

pandas/tests/api/test_api.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ class TestPDApi(Base, tm.TestCase):
3333
# top-level sub-packages
3434
lib = ['api', 'compat', 'computation', 'core',
3535
'indexes', 'formats', 'pandas',
36-
'test', 'tools', 'tseries',
36+
'test', 'tools', 'tseries', 'sparse',
3737
'types', 'util', 'options', 'io']
3838

3939
# top-level packages that are c-imports, should rename to _*
4040
# to avoid naming conflicts
41-
lib_to_rename = ['algos', 'hashtable', 'tslib', 'msgpack', 'sparse',
42-
'json', 'lib', 'index', 'parser']
41+
lib_to_rename = ['algos', 'hashtable', 'tslib',
42+
'lib', 'index']
4343

4444
# these are already deprecated; awaiting removal
45-
deprecated_modules = ['stats', 'datetools']
45+
deprecated_modules = ['stats', 'datetools', 'parser', 'json']
4646

4747
# misc
4848
misc = ['IndexSlice', 'NaT']
@@ -225,3 +225,19 @@ def test_deprecation_access_obj(self):
225225
with tm.assert_produces_warning(FutureWarning,
226226
check_stacklevel=False):
227227
pd.datetools.monthEnd
228+
229+
230+
class TestJson(tm.TestCase):
231+
232+
def test_deprecation_access_func(self):
233+
with tm.assert_produces_warning(FutureWarning,
234+
check_stacklevel=False):
235+
pd.json.dumps([])
236+
237+
238+
class TestParser(tm.TestCase):
239+
240+
def test_deprecation_access_func(self):
241+
with tm.assert_produces_warning(FutureWarning,
242+
check_stacklevel=False):
243+
pd.parser.na_values

pandas/tests/frame/test_to_csv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010
from pandas.compat import (lmap, range, lrange, StringIO, u)
11-
from pandas.parser import ParserError
11+
from pandas.io.common import ParserError
1212
from pandas import (DataFrame, Index, Series, MultiIndex, Timestamp,
1313
date_range, read_csv, compat, to_datetime)
1414
import pandas as pd

0 commit comments

Comments
 (0)