Court cases and tables of them.
Contents
Case: the text and information of one case, ready to be parsed.
load_cases: loads a table of parsed cases.
save_cases: saves a table of parsed cases.
tidy: gives columns with missing values the right type.
_LIST_COLUMNS_FILE: the name of the file, saved beside a CSV file of
cases, that lists the columns that held lists, so that load_cases
can restore them. "{stem}" is replaced with the name of the CSV file
without its extension.
_SEPARATOR: the text between the items of a list when a table is saved as
a CSV file.
_WHOLE_NUMBERS: columns of whole numbers that may be missing for some
cases, which tidy gives the "Int64" type.
_is_list: returns whether a value is a list or tuple.
_unjoin: returns text saved by save_cases as a list again.
Case(id, source, sections=dict(), metadata=dict(), path=None)
dataclass
¶
The text and information of one case, ready to be parsed.
Readers (such as courtlistener.read_case and lexis.read_case) make
cases from files, and a Parser turns each case into a row of a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
a unique name for the case, which becomes the row's label in the table (such as the CourtListener cluster id or the file name). |
required |
source
|
str
|
where the case came from: "court_listener" or "lexis_nexis". |
required |
sections
|
dict[str, str]
|
sections of text that rules search, by name (such as
"party", "disposition", and "opinion"). Defaults to an empty
|
dict()
|
metadata
|
dict[str, Any]
|
information that needs no parsing (such as the date filed
from CourtListener), by the name of its column. These values are
used instead of anything rules find with the same names. Defaults
to an empty |
dict()
|
path
|
Path | None
|
the file the case came from. Defaults to |
None
|
load_cases(path)
¶
Loads a table of parsed cases saved by save_cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
path to a CSV or parquet file. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, labeled by "case_id". Columns that held lists are lists again, and the ids of cases are text, as they were (in the labels and in a "case_id" column, which a table of judges' votes has). |
Source code in src/courtpy/cases.py
save_cases(data, path)
¶
Saves a table of parsed cases.
A CSV file can be opened in a spreadsheet. Lists (such as the judges on a
panel) are written as text, with "; " between the items, and the names of
those columns are saved beside the file (as "{name}.lists.json") so that
load_cases can restore them. A parquet file (which needs the optional
pyarrow package) keeps lists and types as they are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
the table. |
required |
path
|
Path | str
|
path to save it to, ending in ".csv" or ".parquet". Its folder is created if needed. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path the table was saved to. |
Source code in src/courtpy/cases.py
tidy(data)
¶
Gives columns of booleans or whole numbers with missing values a type.
pandas stores a column of booleans with missing values (such as
"published", which is unknown for some cases) as plain objects, and a
column of whole numbers with missing values (such as "year") as decimals.
Such columns become the "boolean" and "Int64" types, which allow missing
values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
a table of cases. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, with those columns changed. |