Skip to content

Commit

Permalink
Add filter by accession
Browse files Browse the repository at this point in the history
  • Loading branch information
dgunning committed Nov 5, 2024
1 parent cf30fd7 commit 20e23ea
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
9 changes: 8 additions & 1 deletion edgar/_filings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
filter_by_form,
filter_by_cik,
filter_by_ticker,
filter_by_accession_number,
listify,
is_start_of_quarter,
InvalidDateException, IntString, DataPager)
Expand Down Expand Up @@ -482,7 +483,8 @@ def filter(self,
filing_date: Optional[str] = None,
date: Optional[str] = None,
cik: Union[IntString, List[IntString]] = None,
ticker: Union[str, List[str]] = None):
ticker: Union[str, List[str]] = None,
accession_number: Union[str, List[str]] = None) -> Optional['Filings']:
"""
Get some filings
Expand All @@ -508,6 +510,7 @@ def filter(self,
:param date: An alias for the filing date
:param cik: The CIK or list of CIKs to filter by
:param ticker: The ticker or list of tickers to filter by
:param accession_number: The accession number or list of accession numbers to filter by
:return: The filtered filings
"""
filing_index = self.data
Expand Down Expand Up @@ -540,6 +543,10 @@ def filter(self,
if ticker:
filing_index = filter_by_ticker(filing_index, ticker)

# Filter by accession number
if accession_number:
filing_index = filter_by_accession_number(filing_index, accession_number=accession_number)

return Filings(filing_index)

def _head(self, n):
Expand Down
10 changes: 10 additions & 0 deletions edgar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'filter_by_form',
'filter_by_cik',
'filter_by_ticker',
'filter_by_accession_number',
'split_camel_case',
'text_extensions',
'binary_extensions',
Expand Down Expand Up @@ -322,6 +323,15 @@ def filter_by_date(data: pa.Table,
return filtered_data


def filter_by_accession_number(data: pa.Table,
accession_number: Union[IntString, List[IntString]]) -> pa.Table:
"""Return the data filtered by accession number"""
# Ensure that forms is a list of strings ... it can accept int like form 3, 4, 5
accession_numbers = [str(el) for el in listify(accession_number)]
data = data.filter(pc.is_in(data['accession_number'], pa.array(accession_numbers)))
return data


def filter_by_form(data: pa.Table,
form: Union[str, List[str]],
amendments: bool = True) -> pa.Table:
Expand Down
8 changes: 6 additions & 2 deletions edgar/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,17 @@ def get_filing_at(self, item: int):
is_inline_xbrl=self.data['isInlineXBRL'][item].as_py()
)


def filter(self,
form: Union[str, List[str]] = None,
amendments: bool = None,
filing_date: str = None,
date: str = None):
date: str = None,
cik: Union[IntString, List[IntString]] = None,
ticker: Union[str, List[str]] = None,
accession_number: Union[str, List[str]] = None,):
# The super filter returns Filings. We want CompanyFilings
res = super().filter(form, amendments, filing_date, date)
res = super().filter(form, amendments, filing_date, date, accession_number)
return CompanyFilings(data=res.data, cik=self.cik, company_name=self.company_name)

def latest(self, n: int = 1):
Expand Down
17 changes: 16 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
filter_by_date,
filter_by_form,
filter_by_cik,
filter_by_accession_number,
InvalidDateException,
client_headers,
CRAWL, CAUTION, extract_dates,
Expand Down Expand Up @@ -180,6 +181,21 @@ def test_filter_by_form():
assert len(filter_by_form(table, form=['10-K', '10-Q', '10-K/A'], amendments=True)) == 4


def test_filter_by_accession_number():
arrays = [pa.array(['a', 'b', 'c', 'd', 'e']),
pa.array([3, 2, 1, 4, 4]),
pa.array(['10-K', '10-Q', '10-K', '10-K/A', '4-K']),
pa.array([3, 2, 1, 4, 4])
]

table = pa.Table.from_arrays(arrays, names=['item', 'value', 'form', 'accession_number'])

assert len(filter_by_accession_number(table, 1)) == 1
assert len(filter_by_accession_number(table, [3, 4], )) == 3
assert len(filter_by_accession_number(table, ['3', 4], )) == 3
assert len(filter_by_accession_number(table, ['3'], )) == 1


def test_filter_by_cik():
arrays = [pa.array(['a', 'b', 'c', 'd', 'e']),
pa.array([3, 2, 1, 4, 4]),
Expand All @@ -196,7 +212,6 @@ def test_filter_by_cik():


def test_filter_by_ticker():

arrays = [pa.array(['a', 'b', 'c', 'd', 'e']),
pa.array([3, 2, 1, 4, 4]),
pa.array(['10-K', '10-Q', '10-K', '10-K/A', '4-K']),
Expand Down

0 comments on commit 20e23ea

Please sign in to comment.