feat: __repr__ + lazy pandas import (#143)#148
Merged
Conversation
Closes #143 - __repr__ on API, Resource, and Datamaxi -> readable repr 'CexCandle(base_url=..., has_key=True)' instead of the default object address; has_key avoids leaking the API key. - Lazy pandas: drop top-level 'import pandas as pd' (it was pulled in via lib/utils on every 'import datamaxi'); import inside the DataFrame code paths, with 'from __future__ import annotations' + a TYPE_CHECKING import so 'pd.DataFrame' return hints still resolve. pandas stays a required dependency (pandas=True is the default) but is no longer loaded until a DataFrame is actually built. Verified: 'import datamaxi' no longer loads pandas; pandas=True still returns a DataFrame (loaded on demand).
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.
Closes #143
Two independent polish items from #143.
1.
__repr__on clientsAPI,Resource, andDatamaxinow render readably instead of<...object at 0x...>:has_keyis a bool — the API key is never included in the repr.2. Lazy pandas import (approach: keep required, import lazily)
pandaswas imported at module top inlib/utils.py(and every resource module), and sinceapi.pypulls inlib/utils, everyimport datamaxiloaded pandas — a heavy dependency users pay for even when they never build a DataFrame.Now the top-level
import pandas as pdis gone; pandas is imported inside the DataFrame code paths. To keep thepd.DataFramereturn hints valid without the eager import, each affected file usesfrom __future__ import annotations(lazy string annotations) plus aTYPE_CHECKING-guarded import for static checkers.pandas stays a required dependency (since
pandas=Trueis the default return, per our discussion — not made an optional extra, which would break the default out of the box). It's just not loaded until a DataFrame is actually built.Verified:
import datamaxi→ pandas not insys.modules; still not loaded even after apandas=Falsecall.pandas=Truestill returns aDataFrame(pandas loaded on demand at that point).Tests
tests/test_repr_and_lazy_pandas.py: repr format + key-non-leak for API/Resource/Datamaxi, and a subprocess-isolated assertion that importing datamaxi doesn't import pandas (isolated because other tests in the session load pandas).pytest -m "not integration": 155 passed, 11 skipped.Known failures
None.