question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: many custom errors / warnings are not exposed in pandas.errors

See original GitHub issue

From https://github.com/pandas-dev/pandas/issues/27553 and https://github.com/pandas-dev/pandas/issues/27522, I quickly looked at how consistent we are with defining errors and warnings in pandas.errors.

So we have a pandas.errors module which is meant to publicly expose our custom exceptions and warnings.

Some are defined there such as PerformanceWarning, UnsortedIndexError, ParserError, … (https://github.com/pandas-dev/pandas/blob/bb6135880e5e453d7701764b9f2e4ad3356a68d7/pandas/errors/__init__.py). But many are not:

  • tslibs.parsing.DateParseError
  • tslibs.period.IncompatibleFrequency
  • pandas/_config/config.py: OptionError
  • pandas/core/base.py: DataError, GroupByError, SpeciicationError
  • pandas/core/common.py: SettingWithCopyError/Warning
  • pandas/core/computation/common/py: NameResolutionError
  • pandas/core/computation/engine.py: NumExprClobberingError
  • pandas/core/computation/ops.py: UndefinedVariableError
  • pandas/core/indexes/base.py: InvalidIndexError
  • pandas/coreindexing.py: IndexingError
  • pandas/io/clipboard/exceptions.py: PyperclipException
  • pandas/io/formats/css.py: CSSWarning
  • pandas/io/msgpack: several exceptions
  • pandas/io/pytables.py: lots of exceptions
  • pandas/io/sql.py: SQLALchemyRequired, DatabaseError
  • pandas/io/stata.py: several warnings

Do we want to move them all to the public pandas.errors module? Are there reasons that some can / should not be moved? Eg should the cython ones be defined in the cython file for performance? Are there certain custom exceptions/warnings that we rather convert in a built-in one instead of publicly exposing them? Do we want to move all the io related ones? (those modules are somewhat public)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jbrockmendelcommented, Feb 21, 2020

brainstorming how to write tests for this, we could do something like:


def get_subclasses_recursive(cls):
    result = []
    subs = cls.__subclasses__()
    result.extend(subs)
    for sub in subs:
        extra = get_subclasses_recursive(sub)
        result.extend(extra)
    return result

all_excs = get_subclasses_recursive(Exception)  # <-- locally after just importing pandas, I get 190 of these

ours = [x for x in all_excs if x.__module__.startswith("pandas.")]  # <-- i get 39 of these

We could use ours and blacklist internal-only classes for the parametrization in tests.test_errors.test_exception_importable

0reactions
dataxerikcommented, May 11, 2022

We could use ours and blacklist internal-only classes for the parametrization in tests.test_errors.test_exception_importable

@jbrockmendel

Hello, I just started to work on this and wanted to follow up on the this because I think I may be on the wrong page. Thank you for the code by the way.

I was initially thinking we would get the pandas exceptions that aren’t in pandas.errors and fail them, unless they’re intentionally not in pandas.errors. There could be a list for the exceptions that are allowed to not be in pandas.errors. But, I was also thinking that might be cumbersome to maintain and maybe the idea is not to enforce all exceptions in pandas.errors.

My idea doesn’t seem to match yours. I’m not quite following how we use ours to blacklist the parametrized exceptions in test_exception_importable

Read more comments on GitHub >

github_iconTop Results From Across the Web

warnings — Warning control — Python 3.11.1 documentation
The warnings filter controls whether warnings are ignored, displayed, or turned into errors (raising an exception). Conceptually, the warnings filter maintains ...
Read more >
How do I catch a psycopg2.errors.UniqueViolation error in a ...
Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single except...
Read more >
pandas.errors.DtypeWarning — pandas 1.5.2 documentation
Raised for a dtype incompatibility. This can happen whenever read_csv or read_table encounter non-uniform dtypes in a column(s) of a given CSV file....
Read more >
How to Fix FutureWarning Messages in scikit-learn
Like many actively maintained software libraries, the APIs often change over time. ... Warning messages are not error messages.
Read more >
Issues When Using auto-py-to-exe - Nitratine
After helping many of people fix issues with auto-py-to-exe and PyInstaller, ... The Terminal Just Opens and Closes But There Are No Errors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found