Module: Polars::Convert
- Included in:
- Polars
- Defined in:
- lib/polars/convert.rb
Instance Method Summary collapse
-
#from_hash(data, schema: nil, schema_overrides: nil, strict: true) ⇒ DataFrame
Construct a DataFrame from a hash of arrays.
-
#from_hashes(data, schema: nil, schema_overrides: nil, strict: true, infer_schema_length: N_INFER_DEFAULT) ⇒ DataFrame
Construct a DataFrame from an array of hashes.
-
#from_numo(data, schema: nil, schema_overrides: nil, orient: nil) ⇒ DataFrame
Construct a DataFrame from a NumPy ndarray.
-
#from_records(data, schema: nil, schema_overrides: nil, strict: true, orient: nil, infer_schema_length: N_INFER_DEFAULT) ⇒ DataFrame
Construct a DataFrame from an array of arrays.
Instance Method Details
#from_hash(data, schema: nil, schema_overrides: nil, strict: true) ⇒ DataFrame
Construct a DataFrame from a hash of arrays.
This operation clones data, unless you pass in a Hash<String, Series>.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/polars/convert.rb', line 44 def from_hash(data, schema: nil, schema_overrides: nil, strict: true) Utils.wrap_df( Utils.hash_to_rbdf( data, schema: schema, schema_overrides: schema_overrides, strict: strict ) ) end |
#from_hashes(data, schema: nil, schema_overrides: nil, strict: true, infer_schema_length: N_INFER_DEFAULT) ⇒ DataFrame
Construct a DataFrame from an array of hashes. This operation clones data.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/polars/convert.rb', line 116 def from_hashes( data, schema: nil, schema_overrides: nil, strict: true, infer_schema_length: N_INFER_DEFAULT ) if !data.any? && !(schema.any? || schema_overrides.any?) msg = "no data, cannot infer schema" raise NoDataError, msg end DataFrame.new( data, schema: schema, schema_overrides: schema_overrides, strict: strict, infer_schema_length: infer_schema_length ) end |
#from_numo(data, schema: nil, schema_overrides: nil, orient: nil) ⇒ DataFrame
Construct a DataFrame from a NumPy ndarray. This operation clones data.
Note that this is slower than creating from columnar memory.
254 255 256 257 258 259 260 261 |
# File 'lib/polars/convert.rb', line 254 def from_numo( data, schema: nil, schema_overrides: nil, orient: nil ) raise Todo end |
#from_records(data, schema: nil, schema_overrides: nil, strict: true, orient: nil, infer_schema_length: N_INFER_DEFAULT) ⇒ DataFrame
Construct a DataFrame from an array of arrays. This operation clones data.
Note that this is slower than creating from columnar memory.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/polars/convert.rb', line 185 def from_records( data, schema: nil, schema_overrides: nil, strict: true, orient: nil, infer_schema_length: N_INFER_DEFAULT ) if !data.is_a?(::Array) msg = ( "expected data of type Array, got #{data.class.name.inspect}" + "\n\nHint: Try passing your data to the DataFrame constructor instead," + " e.g. `Polars::DataFrame.new(data)`." ) raise TypeError, msg end Utils.wrap_df( Utils.sequence_to_rbdf( data, schema: schema, schema_overrides: schema_overrides, strict: strict, orient: orient, infer_schema_length: infer_schema_length ) ) end |