Skip to content

Commit a50cff5

Browse files
committed
API: expose pandas.api.exceptions
xref pandas-dev#14800
1 parent d0a281f commit a50cff5

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+23
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ fixed-width text files, and :func:`read_excel` for parsing Excel files.
5353
pd.read_fwf(StringIO(data)).dtypes
5454
pd.read_fwf(StringIO(data), dtype={'a':'float64', 'b':'object'}).dtypes
5555

56+
57+
.. _whatsnew_0200.enhancements.dev_api_exceptions:
58+
59+
pandas development API
60+
^^^^^^^^^^^^^^^^^^^^^^
61+
62+
In 0.19.0, we introduced standard sub-package to present a public API, see :ref:`here <whatsnew_0190.dev_api>`.
63+
We are adding ``pandas.api.exceptions`` so to expose supported exceptions and warnings. (:issue:`14800`)
64+
65+
The following are now part of this API:
66+
67+
.. ipython:: python
68+
69+
import pprint
70+
from pandas.api import exceptions
71+
excs = [ e for e in dir(exceptions) if not e.startswith('_') ]
72+
pprint.pprint(excs)
73+
74+
.. note::
75+
76+
These existing definitions for these are deprecated and will be removed in a future version.
77+
78+
5679
.. _whatsnew_0200.enhancements.groupby_access:
5780

5881
Groupby Enhancements

pandas/api/exceptions/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
""" public toolkit API """
2+
3+
from pandas.core.common import (PandasError, PerformanceWarning,
4+
AmbiguousIndexError, UnsupportedFunctionCall,
5+
UnsortedIndexError)
6+
from pandas.tslib import OutOfBoundsDatetime
7+
from pandas.io.common import (ParserError, DtypeWarning,
8+
EmptyDataError, ParserWarning)

pandas/tests/api/test_api.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import pytest
34
import numpy as np
45

56
import pandas as pd
@@ -214,6 +215,26 @@ def test_removed_from_core_common(self):
214215
self.assertRaises(AttributeError, lambda: getattr(com, t))
215216

216217

218+
class TestException(object):
219+
220+
@pytest.mark.parametrize(
221+
"exc", ['PandasError', 'AmbiguousIndexError',
222+
'UnsupportedFunctionCall', 'UnsortedIndexError', 'OutOfBoundsDatetime',
223+
'ParserError', 'PerformanceWarning', 'DtypeWarning',
224+
'EmptyDataError', 'ParserWarning'])
225+
def test_exception_importable(self, exc):
226+
from pandas.api import exceptions
227+
assert getattr(exceptions, exc)
228+
229+
def test_catch_oob(self):
230+
from pandas.api import exceptions
231+
232+
try:
233+
pd.Timestamp('15000101')
234+
except exceptions.OutOfBoundsDatetime:
235+
pass
236+
237+
217238
class TestDatetools(tm.TestCase):
218239

219240
def test_deprecation_access_func(self):

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ def pxd(name):
623623
packages=['pandas',
624624
'pandas.api',
625625
'pandas.api.types',
626+
'pandas.api.exceptions',
626627
'pandas.compat',
627628
'pandas.compat.numpy',
628629
'pandas.computation',

0 commit comments

Comments
 (0)