8000 API: expose pandas.errors by jreback · Pull Request #15541 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

API: expose pandas.errors #15541

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

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DOC: better docs on infer_type
  • Loading branch information
jreback committed Apr 3, 2017
commit e91901db66289261f105427aaefe7843478ca581
17 changes: 11 additions & 6 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ will be removed from the ``*.common`` locations in a future release. (:issue:`15

The following are now part of this API:

.. ipython:: python

import pprint
from pandas import errors
excs = [ e for e in dir(errors) if not e.startswith('_') ]
pprint.pprint(excs)
.. code-block:: python

['AmbiguousIndexError',
'DtypeWarning',
'EmptyDataError',
'OutOfBoundsDatetime',
'ParserError',
'ParserWarning',
'PerformanceWarning',
'UnsortedIndexError',
'UnsupportedFunctionCall']

.. _whatsnew_0200.enhancements.groupby_access:

Expand Down
61 changes: 47 additions & 14 deletions pandas/_libs/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,42 @@ cdef _try_infer_map(v):
return None


def infer_dtype(object _values):
def infer_dtype(object value):
"""
we are coercing to an ndarray here
Effeciently infer the type of a passed val, or list-like
array of values. Return a string describing the type.

Parameters
----------
value : scalar, list, ndarray, or pandas type

Returns
-------
string describing the common type of the input data.
Results can include:
- floating
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small rst thing: no indentation needed, and white line before the list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, though I don't think we actually have a doc-generation section for pandas.api ATM. (i'll make an issue).

- integer
- mixed-integer
- mixed-integer-float
- complex
- categorical
- boolean
- datetime64
- datetime
- date
- timedelta64
- timedelta
- time
- period
- string
- unicode
- bytes
- mixed

Raises
------
TypeError if ndarray-like but cannot infer the dtype

"""

cdef:
Expand All @@ -229,27 +262,27 @@ def infer_dtype(object _values):
ndarray values
bint seen_pdnat = False, seen_val = False

if isinstance(_values, np.ndarray):
values = _values
elif hasattr(_values, 'dtype'):
if isinstance(value, np.ndarray):
values = value
elif hasattr(value, 'dtype'):

# this will handle ndarray-like
# e.g. categoricals
try:
values = getattr(_values, '_values', getattr(
_values, 'values', _values))
values = getattr(value, '_values', getattr(
value, 'values', value))
except:
val = _try_infer_map(_values)
if val is not None:
return val
value = _try_infer_map(value)
if value is not None:
return value

# its ndarray like but we can't handle
raise ValueError("cannot infer type for {0}".format(type(_values)))
raise ValueError("cannot infer type for {0}".format(type(value)))

else:
if not isinstance(_values, list):
_values = list(_values)
values = list_to_object_array(_values)
if not isinstance(value, list):
value = list(value)
values = list_to_object_array(value)

values = getattr(values, 'values', values)
val = _try_infer_map(values)
Expand Down
0