Skip to content

Commit 73a2c07

Browse files
author
Scott Sanderson
committed
MAINT: Use factorize_strings to uniquify in get_rates_columnar.
This handles None more gracefully than coercing to numpy's string type, and it also ensures that we satisfy the documented input types for get_rates.
1 parent a7e0898 commit 73a2c07

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

zipline/data/fx/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas as pd
55

66
from zipline.utils.sentinel import sentinel
7+
from zipline.lib._factorize import factorize_strings
78

89
DEFAULT_FX_RATE = sentinel('DEFAULT_FX_RATE')
910

@@ -137,8 +138,11 @@ def get_rates_columnar(self, rate, quote, bases, dts):
137138

138139
# TODO: Casting `bases` to str here is a temporary fix for the bug
139140
# where having any `None` in `bases` causes `np.unique` to error.
140-
unique_bases, bases_ix = np.unique(bases.astype(str),
141-
return_inverse=True)
141+
bases_ix, unique_bases, _ = factorize_strings(
142+
bases,
143+
missing_value=None,
144+
sort=True,
145+
)
142146
unique_dts, dts_ix = np.unique(dts.values, return_inverse=True)
143147
rates_2d = self.get_rates(
144148
rate,

0 commit comments

Comments
 (0)