Skip to content

feat: __repr__ + lazy pandas import (#143)#148

Merged
martinkersner merged 1 commit into
mainfrom
feat/repr-polish
Jul 3, 2026
Merged

feat: __repr__ + lazy pandas import (#143)#148
martinkersner merged 1 commit into
mainfrom
feat/repr-polish

Conversation

@martinkersner

Copy link
Copy Markdown
Member

Closes #143

Two independent polish items from #143.

1. __repr__ on clients

API, Resource, and Datamaxi now render readably instead of <...object at 0x...>:

Datamaxi(base_url='https://api.datamaxiplus.com', has_key=True)
CexCandle(base_url='https://api.datamaxiplus.com', has_key=True)

has_key is a bool — the API key is never included in the repr.

2. Lazy pandas import (approach: keep required, import lazily)

pandas was imported at module top in lib/utils.py (and every resource module), and since api.py pulls in lib/utils, every import datamaxi loaded pandas — a heavy dependency users pay for even when they never build a DataFrame.

Now the top-level import pandas as pd is gone; pandas is imported inside the DataFrame code paths. To keep the pd.DataFrame return hints valid without the eager import, each affected file uses from __future__ import annotations (lazy string annotations) plus a TYPE_CHECKING-guarded import for static checkers.

pandas stays a required dependency (since pandas=True is 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 in sys.modules; still not loaded even after a pandas=False call.
  • pandas=True still returns a DataFrame (pandas loaded on demand at that point).

Tests

  • New 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.
  • black + flake8 clean.

Known failures

None.

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).
@martinkersner martinkersner merged commit 9c5ae43 into main Jul 3, 2026
5 checks passed
@martinkersner martinkersner deleted the feat/repr-polish branch July 3, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polish: __repr__ on clients + make pandas an optional extra

1 participant