FIX/options.expirations returns an empty DataFrame when filtering columns#27
Open
MarketDataDev03 wants to merge 3 commits into
Open
FIX/options.expirations returns an empty DataFrame when filtering columns#27MarketDataDev03 wants to merge 3 commits into
MarketDataDev03 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #27 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 52 52
Lines 2281 2284 +3
=========================================
+ Hits 2281 2284 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix:
options.expirationsreturns an empty DataFrame when filtering columnsCloses #23
Summary
options.expirations(..., columns=["expirations"])returned an empty DataFrame,and the
INTERNALoutput format crashed on partial API responses. Both stem fromthe same trigger: the
columnsparameter is applied server-side, so requestingcolumns=["expirations"]makes the API respond with only{"s": "ok", "expirations": [...]}— without the
updatedfield the SDK assumed was always present.This PR fixes both failure modes and adds regression tests.
Problem
Two distinct bugs:
Empty DataFrame (primary). The resource always forced
index_columns=["expirations"]. Whenexpirationsis the only column returned,the pandas handler promotes it to the index via
set_index, leaving theDataFrame with zero data columns — so it looks empty even though the data is
there (in the index).
INTERNALcrash on partial responses (secondary).OptionsExpirationsrequired the
updatedfield. A response missing it (e.g. a filtered/partialresponse) raised
TypeError, which@handle_exceptionsturned into aMarketDataClientErrorResult.Changes
resources/options/expirations.py— primary fixStop forcing
expirationsinto the index when the user explicitly filters columns.The default behavior (no
columnsfilter →expirationsas index) is unchanged.output_types/options_expirations.py— secondary fixMake
updatedoptional and skip conversion when it is absent.output_handlers/base.py— required follow-on fixChanging
updatedto the PEP 604 uniondatetime | Nonebroke date-columndetection:
_type_includesonly recognizedtyping.Union, butX | Nonehasorigin
types.UnionType. Without this,updatedstopped being converted to adatetime and broke two pre-existing DataFrame tests. Now both union forms are
handled.
Testing
Added 4 tests in
src/tests/test_options_expirations.py:test_options_expirations_optional_updated— dataclass acceptsupdated=None.test_get_options_expirations_columns_filter_dataframe_pandas— filtered DataFrameis not empty; compared against a full expected DataFrame via
assert_frame_equal.test_get_options_expirations_columns_filter_dataframe_polars— regression guard(polars never had the bug).
test_get_options_expirations_partial_response_internal—INTERNALparses aresponse missing
updated, leaving itNone.Developed with a TDD red → green cycle.
Full suite green — no regressions.
Files changed
src/marketdata/resources/options/expirations.pysrc/marketdata/output_types/options_expirations.pyupdatedmade optionalsrc/marketdata/output_handlers/base.pyX | Nonein date detectionsrc/tests/test_options_expirations.py