File: warns.py

package info (click to toggle)
python-agate 1.13.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,008 kB
  • sloc: python: 8,578; makefile: 126
file content (47 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import warnings


class NullCalculationWarning(RuntimeWarning):  # pragma: no cover
    """
    Warning raised if a calculation which can not logically
    account for null values is performed on a :class:`.Column` containing
    nulls.
    """
    pass


def warn_null_calculation(operation, column):
    warnings.warn('Column "{}" contains nulls. These will be excluded from {} calculation.'.format(
        column.name,
        operation.__class__.__name__
    ), NullCalculationWarning, stacklevel=2)


class DuplicateColumnWarning(RuntimeWarning):  # pragma: no cover
    """
    Warning raised if multiple columns with the same name are added to a new
    :class:`.Table`.
    """
    pass


def warn_duplicate_column(column_name, column_rename):
    warnings.warn('Column name "{}" already exists in Table. Column will be renamed to "{}".'.format(
        column_name,
        column_rename
    ), DuplicateColumnWarning, stacklevel=2)


class UnnamedColumnWarning(RuntimeWarning):  # pragma: no cover
    """
    Warning raised when a column has no name and an a programmatically generated
    name is used.
    """
    pass


def warn_unnamed_column(column_id, new_column_name):
    warnings.warn('Column %i has no name. Using "%s".' % (
        column_id,
        new_column_name
    ), UnnamedColumnWarning, stacklevel=2)